Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

adding dynamic script tag

Status
Not open for further replies.

hurjo

Programmer
May 1, 2009
2
hi, iv tried the following for a couple of days everytime changing some code here and there in vain...any help is accepted...the problem right now is that nothing gets executed it seems...

im trying to add a dynamic script tag that uses google search api...

Code:
var head = document.commandDispatcher.focusedWindow.document.getElementsByTagName("head");
var s = document.createElement("script");
s.type = "text/javascript";
s.src= '[URL unfurl="true"]http://www.google.com/jsapi';[/URL]
var ccc = '<script language="Javascript" type="text/javascript">
google.load("search", "1");
function OnLoad() {
var searchControl = new google.search.WebSearch();
searchControl.execute("hello");
searchControl.setSearchCompleteCallback(null, 
    function gotResults(){
     var url = searchControl.results[0].url;
    window.open(url);
     }
 );
}

google.setOnLoadCallback(OnLoad);
</script>';

s.innerhtml += ccc;
head[0].appendChild(s);
 
I'm surprised you're not getting a syntax error from the missing quote at the end of this line:

Code:
var ccc = '<script language="Javascript" type="text/javascript">

Perhaps load your page in Firefox and look in the error console...

Dan



Coedit Limited - Delivering standards compliant, accessible web solutions

Dan's Page [blue]@[/blue] Code Couch:
Code Couch Tech Snippets & Info:
 
no i just put code in that format to be readable...it is on one line in my .js file....

the ' ends at </script>'


i figured out what the problem was...i had to use " where there was ' and ' where there was " for the innerhtml.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top