the website in the main document includes a javascript file using the following statement:
<script src="/somescript.js" type="text/javascript"></script>
There's also a link on the website that executes a javascript function defined in the incuded file. It looks like:
<a href="javascript:functionname('parm1', 'parm2');" <img src="http://.../button.png" id="pushme" alt="" height="80" width="200"> </a>
How can i execute functionname('parm1', 'parm2');
in the context of the main document from a firefox sidebar?
What i've tried so far is:
mainWindow[functionname]
to obtain a pointer to the js function, but it always returns null, even if the page was loaded completely. (Does this happen because the javascript source is included from a seperate file?)
contentDocument.getElementById("parentdiv").getElementsByTagName('a')[0].click();
to invoke the method, but click does not seem available. (Is there a way to make the link click()-able?)
Or is there an other way to get the js function executed?
Thanks for your support!
you can't get a handle to the window because it isn't an instance variable of the current window. You can get a reference to the window by using window.open()
and storing the resulting handle in variable.
What i've tried so far is: mainWindow[functionname] to obtain a pointer to the js function, but it always returns null, even if the page was loaded completely. (Does this happen because the javascript source is included from a seperate file?
It doesn't matter where the file is included from, the function comes into being in the browser's mind when its definition is executed.
To make the link 'clickable' you can just call it with the window handle:
var myWindow = window.open("foo.html");
<a href="javascript:myWindow.functionname('parm1', 'parm2');">
Of course, we shouldn't be using inline javascript, but its ok for a quick example. :)