Well, the script needs all of its elements available, before it can initialize. The safe way to do this is onload. However, since you are not (or at least probably should not) be using the persistence feature, you can try this idea which works locally here and in web simulation. Get rid of this from the end of the script:
Code:
if (window.addEventListener)
window.addEventListener("load", do_onload, false)
else if (window.attachEvent)
window.attachEvent("onload", do_onload)
else if (document.getElementById)
window.onload=do_onload
and substitute this:
Code:
function init(){
if (document.getElementById('last')){
do_onload();
clearInterval(startit)
}
else if (startit==0)
startit=setInterval("init();", 250)
}
var startit=0
init();
This will require you to also give an id of 'last' to the last element in the content script's markup. In the demo, this is here:
Code:
<div id="sc4" class="tabcontent">
<form action="http://www.google.com/search" method="get" onSubmit="this.q.value='site:www.dynamicdrive.com '+this.qfront.value">
<p>Search Dynamic Drive:<br />
<input name="q" type="hidden" />
<input id="last" name="qfront" type="text" style="width: 180px" /> <input type="submit" value="Search" /></p>
</form>
</div>
If there is no convienient spot for that, you can make one, using an empty span tag after the last content block:
Code:
<div id="sc4" class="tabcontent">
<form action="http://www.google.com/search" method="get" onSubmit="this.q.value='site:www.dynamicdrive.com '+this.qfront.value">
<p>Search Dynamic Drive:<br />
<input name="q" type="hidden" />
<input name="qfront" type="text" style="width: 180px" /> <input type="submit" value="Search" /></p>
</form>
</div><span id="last"></span>
This may even work with the optional persistence feature but, I haven't tested that and, even without that it may fail in actual live use, so test it out. The idea is, instead of waiting until the page is loaded, simply waiting until the markup for the script is loaded.
Bookmarks