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
OpsterOpster 

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');

 Alert(obj.innerHTML);

 

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. 

SteveBowerSteveBower

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.

OpsterOpster

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.

SteveBowerSteveBower

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.

OpsterOpster
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.
SteveBowerSteveBower
I guess it's not clear to me what functionality you're trying to achieve.  My apologies and best of luck.  Steve.
OpsterOpster
I need my javascript to find every instance of a phone number on the current page.
OpsterOpster

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() ?

sfdcfoxsfdcfox

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 server.salesforce.com, while Visualforce runs on server.force.com. 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:

 

alert(document.body.innerHTML)

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.

cafe2cafe2

Hi,

 

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:

 

location.replace('/_ui/core/email/author/EmailAuthor?p2_lkid={!Account.Id}&rtype=00Q&retURL={!Account.Id}&template_id=00X80000001EGNN&p2={!Account.Clinic_Email__c}&p2_mod=1&p5=')

 

location.replace('/_ui/core/email/author/EmailAuthor?p2_lkid={!Account.Id}&rtype=00Q&retURL={!Account.Id}&template_id=00X80000001EGNN&p2={!Account.Clinic_Email__c}&p5=')

 

Any suggestions?

 

Thanks in advance!

 

gleebsgleebs

 

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;

 

or

 

window.opener.reload();

 

Basically, window.opener is null.

 

Has anyone devised a work around for this?

 

Thanks

 

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

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.

 

Example:

 

 

{!RequireScript("/js/functions.js")}
{!RequireScript("/soap/ajax/16.0/connection.js")}

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

function createForm()
{ form = document.createElement('form')
  form.name = 'lookupform'
  form.id = 'lookupform'
  document.body.appendChild(form)
}

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

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

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

  if(!document.elementsAddedToPage)
  { createForm()
    addElement('lookup_lkid','')
    addElement('lookup_lkold','')
    addElement('lookup_lktp','005')
    addElement('lookup_lspf','0')
    addElement('lookup_mod','0')
    addElement('lookup','')
    document.elementsAddedToPage = true
  }
  openLookup(
    '/_ui/common/data/LookupPage?lknm=lookup'+
    '&lkfm=lookupform&lkrf=&sn=1&lktp='+
    document.getElementById('lookup_lktp').value,
    670,
    document.getElementById('lookup_mod').value,
    '&lksrch='+
    escapeUTF(document.getElementById('lookup').value),
    'maxw')
  window.addEvent(window,'focus',doAction,true)
}

setupTransfer()