User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 361,045 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 2,101 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 2429 | Replies: 1
Reply
Join Date: Jul 2005
Posts: 1
Reputation: arstein is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
arstein arstein is offline Offline
Newbie Poster

Forcing a script to load in Safari -- help needed

  #1  
Jul 11th, 2005
Hi,

I've been beating my head against my inability to force Safari to dynamicall
y load an external Javascript file, and was wondering if anyone has any advi
ce. My current code works fine in Firefox and IE:

var e = document.createElement("script");

e.src = url;
e.type="text/javascript";
document.getElementsByTagName("head")[0].appendChild(e);

I want the script to load and then execute. Any suggestions?
AddThis Social Bookmark Button
Reply With Quote  
Join Date: May 2005
Location: Wellington, New Zealand
Posts: 182
Reputation: alpha_foobar is an unknown quantity at this point 
Rep Power: 4
Solved Threads: 3
alpha_foobar's Avatar
alpha_foobar alpha_foobar is offline Offline
Junior Poster

Re: Forcing a script to load in Safari -- help needed

  #2  
Jul 17th, 2005
I am afraid that I do not have a safari browser to test on. However, I did find, when testing with IE and Firefox, that I had to wait some time for some scripts to be loaded.

I used this code *similar* to this to load script files and check the function I want to load exists... sometimes it can take a few iterations before the function is available to the web page.

function importLibFile(file){
	var e = document.createElement("script");
	e.src = file;
	e.type="text/javascript";
	document.getElementsByTagName("head")[0].insertBefore(e, document.getElementsByTagName("script")[0]);
}

function loadPackage(func, libFile){
	if(document.libraries && !document.libraries[libFile]){
		document.libraries[libFile] = true;
		importLibFile(libFile);
	}
	try {
		func(null, function(s){alert(s);});
		document.getElementsByTagName("body").item(0).innerHTML += (libFile + " package loaded." +"<br/>");
	} catch(exception) {
		document.getElementsByTagName("body").item(0).innerHTML += ("Loading package " + libFile +"<br/>");
		// while appfunction doesn't load
		setTimeout(function(){ loadPackage(func, libFile); }, 250);
	}
}
Last edited by alpha_foobar : Jul 17th, 2005 at 9:49 pm. Reason: formatting
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

DaniWeb JavaScript / DHTML / AJAX Marketplace
Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 11:23 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC