0

So what I am trying to do is when my team and I are in our salesforce program, I want the ability to click on a "Marklet" (javascript within a bookmark) that will automatically scan the source code of the page, find the "CID" section and grab whatever is within that text box (that is locked so it only changes when viewing another customer's salesforce page) and add it to the end of my url that will then search it within our MCC account.

Here is what I have got so far:

javascript:(onload=function MCC() {
var customer=document.getElementById("00N800000052k7r_ilecell");
if (customer != null) {document.getElementsByTagName('00N800000052k7r_ileinner').innerHTML 
    =window.open('https://adwords.google.com/mcm/Mcm?authuser=0&__u=6093584462&__c=2744111912#c.ac:s._'+encodeURIComponent(customer));}})();

Anytime I use this code, it pulls up the new tab and goes to the correct URL, but it always thinks I am searching for [object HTMLTableCellElement]. How do I correct this?

1 Answers1

0

getElementsByClassName returns an array, try:

document.getElementsByClassName('CID')[0]

or use an id and document.getElementById

dhc
  • 647
  • 8
  • 17
  • I tried this just now and it still isn't working correctly. I have updated my code in the original post above and the new search query it is returning upon click on said "Marklet". – Ryan Adams Nov 19 '14 at 21:26
  • You have to change it in both places... or if it's the same element, just use `customer` in the second reference... – dhc Nov 19 '14 at 21:57
  • it also looks like you're setting the HTML of the element to the return value of the `window.open` call -- is that right? (see https://developer.mozilla.org/en-US/docs/Web/API/Window.open) – dhc Nov 19 '14 at 22:02