function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion

Custom Button JavaScript cant see parent window HTML?

I am trying to grab an email address from the parent window when my Custom Button is clicked on a Lead Detail page.  But it seems like I am doing something wrong in my JavaScript to get at the parent window's HTML (Lead Detail page).   Does anyone know the correct syntax to get the HTML of the Lead Detail page when my JavaScript is invoked?


Here is my code snippet:


 var obj = parent.document.getElementsByTagName('td');



Whatever I am getting back issnt the HTML of the Lead Detail page.   And I have tried different combinations of window.parent, parent.window etc etc with no luck.


thanks in advance. 


Can't you just pass the e-mail address to your Javascript as part of the button definition?   Why have the Javascript try to go get the whole page, then have to parse through it, etc.; that seems an odd solution.


Best, Steve.


If the Lead has multiple email addresses I want to grab all of them.   Is there a way to place a custom button next to each email address and pass in the email it is associated with?   I would love to see how if it is possible.


Well, I'm not sure I'm 100% gathering what you're trying to do.  But, if your Lead object has two (for example) custom fields:  email1, and email2, then you should be able to create a button which can call an s-control or visualforce page and pass along arguments of the form:     xxxxxx?e1={!email1__c}&e2={!email2__c}


Your code on the receiving end can then query the parameters and process them as you like.


That's not giving you one button per e-mail address, but perhaps this suffices.


Best, Steve.

I need the email's to either be populated into a drop down list to be selected individually before clicked and POSTED to the remote server, or I need an individual button next to each email address.
I guess it's not clear to me what functionality you're trying to achieve.  My apologies and best of luck.  Steve.
I need my javascript to find every instance of a phone number on the current page.

Correction, I meant email address.   I have a regex for email addresses.  This code works locally on my workstation on a test HTML page, but when i load the javascript into my OnClick for my Custom Button, it no longer seems to have access to the Lead Page's HTML.   Say I wanted to highlight all email addresses in RED text color...  why does my code work on the local workstation but not on SFDC?   It comes down to not having access to the Lead Page itself or at least I dont know the correct syntax for accessing the LeadPage.document.body.


Anyone know how to grab that so I can properly run GetElementByID() ?


One of two things...

1) If you're using Visualforce, and it's in an IFRAME, you're completely out of luck. Salesforce runs on, while Visualforce runs on Since they're different domains, browser security prohibits accessing the parent object. There is no workaround for this problem.

2) If you're using a custom button (i.e. Setup | App Setup | Customize | Leads | Buttons and Links), please note that the button runs in the same page as the lead detail screen. You do not need to access parent, which should ordinarily be null because there is no parent window to the UI in normal conditions. I wrote a quick button that did work, and it looked like this:



I do hope this information helps you resolve your problem. If not, let me know, and I'll see what I can do to provide further help.




I'm a code novice and am not sure if my question is answered here already. I've created a custom button to email from the account page, but can't get the "To" field to populate with the email address I have in a custom field: !{!Account.Clinic_Email__c}. Here are some things I've tried:






Any suggestions?


Thanks in advance!




I am using a custom button that pops a VF page.  After the user is done with interacting with the popup, I'd like to close the popup and refresh the parent page.


As this post indicates, you cannot access the parent window from the popup via javascript.  At least not by doing..


window.opener.location.href = window.opener.location.href;






Basically, window.opener is null.


Has anyone devised a work around for this?




window.opener.location.href = window.opener.location.href;

What I've done previously is to instead inject my own watchdog event to check when the window closes. This was when I attempted (successfully) to hijack the Lookup Window functionality for my own nefarious plans. Basically, you have the parent window create a variable for the window, then assign an event handler to it, or watch it periodically for when the window is flagged as closed.






var recordsToTransfer = {!GetRecordIds($ObjectType.Opportunity)}

function createForm()
{ form = document.createElement('form') = 'lookupform' = 'lookupform'

function addElement(name,value)
{ form = document.getElementById('lookupform')
  element = document.createElement('input') = name = name
  element.type = 'hidden'
  element.value = value
function doAction()
{ window.removeEvent(window,'focus',doAction,true)
  userToTransferTo = document.getElementById('lookup_lkid').value
  if(userToTransferTo == '')

  recordArray = new Array()
  for(recordToTransfer in recordsToTransfer)
  { var Opportunity = new sforce.SObject("Opportunity")
    Opportunity["Id"] = recordsToTransfer[recordToTransfer]
    Opportunity["OwnerId"] = userToTransferTo
try {
  results = sforce.connection.update(recordArray)
} catch(e)
{ alert(e)
} =

function setupTransfer()
{ if(recordsToTransfer.length < 1)
  { alert('Please select at least one row!')

  { createForm()
    document.elementsAddedToPage = true