View Full Version : Ajax Content - Reload Scripts

09-10-2007, 03:30 PM
1) Script Title: Ajax Content

2) Script URL (on DD): http://www.dynamicdrive.com/dynamicindex17/ajaxcontent.htm

3) Describe problem:
...this function will remember when a CSS or JS file has already been loaded and applied to the page, and won't load the same file again even if the link that invokes it is clicked on multiple times.
I need to be able to have the loadobjs JS reloaded/re-invoked whenever the relevant link is clicked on the main page, as opposed to only loading it the first time... is there a way? :confused:

Many thanks!

09-11-2007, 04:36 AM
Is there a reason for this? The approach will be different based on what you're trying to accomplish.

09-11-2007, 08:42 AM
Yes... i'm using the swfobject script to display flash in the ajax div. It works the first time I load the page, but on subsequent attempts, only the html within the ajax div loads - presumably because it's not reloading the javascript.

09-11-2007, 08:57 AM
Once the script is initially added to the page, it should be usable as many times as needed by whatever is using it. It's no different than physically adding the script to your page, so unless you need to reload the page each time even in the later case to get the whole thing to work again, you shouldn't need to re-add the script each time.

Perhaps a link to the problem page would help.

09-11-2007, 09:10 AM
Thanks for the quick response. Unfortunately i can't link to the page, but maybe it would help if I posted the relevant code?

The code attached to the link:

onclick="slideIt('pages/videos.html', 'content', 'js/writevideo.js')"

The slideIt function, which let's me load the content via ajaxpage, and slide it in using mootools:

function slideIt(url, div, obj){
ajaxpage(url, div);

The code from the file "writevideo.js" to write the flash to the ajax div:

var so = new SWFObject("pages/videos.swf", "swf", "400", "410", "8", "#FFFFFF");
so.addParam ("menu", "false");
so.addParam ("scale", "noscale");
so.addParam ("wmode", "transparent");
so.write ("videoholder");

The other scripts I neeed (mootools, ajaxloader and swfobject) are already loaded through the head of the main page.

I hope this makes some kind of sense! Thanks again.

09-12-2007, 08:29 AM
What stands out to me as being potentially problematic is writevideo.js. Does the external page being fetched by Ajax Content reference this file to write out the Flash onto the page? If writevideo.js does this by using document.write (check the source of the .js file), then it won't work when fetched via Ajax in general. This is because document.write is one of those methods in JavaScript that can only be called on runtime, or when the page first loads (synchronous). This, versus the asynchronous nature of Ajax.

There may be ways to get around this, but it really depends on knowing what exactly writevideo.js does.

09-12-2007, 10:05 AM
The code pasted above is all that exists in writevideo.js, and the video.html page only consists of a title and the videoholder div (which eventually contains the swf).

I guess the easy way around this problem is just to use the default code provided by Flash for embedding the swf, rather than using the swfobject script to write it to the page.

09-12-2007, 10:48 PM
Another way to get around fetching external pages with scripts on it that run synchronously (inline) is to put that page in an iframe. See this thread: http://www.dynamicdrive.com/forums/showthread.php?t=23799