1
votes

I've developed a simple google chrome extension, that edits current page textbox values.

This is my content.js page

window.addEventListener ("load", myMain, false);

function myMain (evt) 
{
	
    try
    {
        var inputs, index;
        inputs = document.getElementsByTagName('input');

        for (index = 0; index < inputs.length; ++index) 
        {
          // deal with inputs[index] element.

	   if(inputs[index].type=='text')
           {
		inputs[index].value='SampleValue';	
	   }   	
        }
	
    }
    catch(e)
    {  		
    }    
}

This works fine for normal HTML pages.

BUT

This does not work for Salesforce visual force pages. I've used document.getElementById('SamplemainPage:mainForm:pageBlock1:pageBlockSection1:myId1').value='Sample Text';

at the bottom of my visualforce page, Then it works and change the value of my text box.

But when i put same code snippet to content.js it does not work.

How it is possible? because it says think content.js as a part of current web page. So i believe it should work

1
how did you include you js ? could you show me? - Joseph M Tsai
"content_scripts": [ { "js": [ "content.js", "jquery.js" ], "matches": [ "<all_urls>"], "run_at": "document_end" - GoogleChrome

1 Answers

0
votes

1.Please upload you js file into static resource and

[https://developer.salesforce.com/docs/atlas.en-us.pages.meta/pages/pages_resources_reference.htm][1]

  1. inlcude script like this

    <apex:includeScript value="{!$Resource.MyJavascriptFile}"/>