Find your content:

Search form

You are here

Why does this Javascript code not work?

 
Share

I have the following Javascript code embedded in my side row

window.onload = new function()
{
hideBtns();
}
function hideBtns()
{
if(document.getElementsByName('edit')[0]!=null){
document.getElementsByName('edit')[0].style.display = 'none';}

if(document.getElementsByName('edit')[1]!=null){
document.getElementsByName('edit')[1].style.display = 'none';}
}

Inspecting the edit button in chrome o/p :

<input value=" Edit " class="btn" title="Edit" name="edit" onclick="navigateToUrl('/001d000000JXhAX/e?retURL=%2F001d000000JXhAX','DETAIL','edit');" type="button">

The script is being called , though I see that the name of the "Edit" button is "edit" when I inspect it is not entering the if(document.getElementsByName('edit')[0]!=null){ block !!!

Any pointers will be a great help!!!


Attribution to: Rao

Possible Suggestion/Solution #1

I am afraid you are likely out of luck. If you are using a Visualforce Area to place the javascript in your sidebar, Salesforce accomplishes this by placing your code in an iframe. This sandboxes the component and prevents it from accessing any other parts of the page. There is another post here detailing the changes Salesforce made to javascript in the sidebar: End of javascript sidebar workarounds?.


Attribution to: dsharrison
This content is remixed from stackoverflow or stackexchange. Please visit https://salesforce.stackexchange.com/questions/5594

My Block Status

My Block Content