I have a pretty specific question. I am trying to implement an onclick and cross domain tracking within a block of text, but it looks like it may need to be put directly into a .js document. I don’t have a lot of JS experience. Basically, the current code looks like:
// JavaScript Document
function popup_no_status(loc)
{
var windowW=1000
var windowH=700
s = "width="+windowW+",height="+windowH+",status=yes, resizable=yes, scrollbars=yes";
mywin = window.open(loc ,'CBE', s);
mywin.focus();
}
What I want to add to this is:
onclick="pageTracker._trackEvent('Button', 'Click', 'QuickSearchWidget'); pageTracker._link(this.href); return false;
Can I just add it to the end of the document before the closing bracket? Any Ideas?
Much appreciated!
As long as the object
pageTrackeris defined and instantiated, you can call its methods like any other function:Also, the variables
windowWandwindowHare pointless in your example code – there is no need to store the string values in a variable if all you’re going to do is concatenate them into another string. Further, unless you intend themywinandsvariables to be global, you should use thevarkeyword before defining them – that restricts the variables to the function scope instead of the global scope (all variables declared in a function without thevarkeyword are considered global).If the code above gives an error like
ReferenceError: pageTracker is not defined, that means that the code in which thepageTrackerobject is defined is either not included on the page, or it has not been instantiated.Now… as for onClick, I am not clear what you’re after here. Do you want this function to run when someone clicks the document? That would get pretty annoying!