Hi Dave,

So in essence, you want to load a "page" (really a fragment of a page)
from the server into a container element and execute the scripts in
the page that comes back?  Good news:  You're working too hard. :-)
Prototype will do that for you if you set Ajax.Updater's "evalScripts"
option[1] to true.

[1] http://www.prototypejs.org/api/ajax/updater

You said you call a function on the page to give it a chance to run
its scripts.  You don't have to do that, any function calls at the
"global" level in the page that comes back will get executed as part
of Prototype's script evaluation.

Here's a demo:
http://pastie.org/297904  (the container page)
http://pastie.org/297905  (the "page" fragment it loads)

In that demo:  The container loads the "newstuff" fragment, Prototype
runs the scripts.  Since the "newstuff" fragment has a global call to
a function, that happens right then and we see the alert.  Once
loaded, the scripts on the fragment and in the main page have access
to each other, it's all the same DOM document.

T.J. Crowder
tj / crowder software / com

On Oct 22, 9:42 am, DaveC <[EMAIL PROTECTED]> wrote:
> This is kind of related to previous post "Dynamic script file
> loading", but I cant solve the following problem. Please help. It's
> basically an IE problem.
> I'm writing an AJAX application where each page of the site is loaded
> dynamically by the client side application. So for example the user
> clicks home, and the client side app makes an AJAX call to the server
> for the content and replaces the contents of a container div with this
> new content. Each page has some Javascript that needs to be
> dynamically added to the page as well, so here I'm adding a script
> element into the container as well. Once all that's done I call a
> predefined onload function in the returned script so that the page
> content can take over and do it's thing (setting up page related
> stuff)
> The difference with the previous post is that my javascript is
> returned in the AJAX call, I have no files to dynamically reference on
> the server, the Javascript comes in the AJAX response.
> BUT the following code hands in IE7 when it gets to the .update and I
> don't know why.. this otherwise works in other browsers.
>             // add html to container.
>             container.update(new_content_html);
>             // add javascript to container.
>             var el_script = new Element('script', { 'language':
> 'JavaScript', 'type':'text/JavaScript' });
>             el_script.update(new_content_js); // ?????? IE7 hangs
> here ?????
>             container.insert( el_script );
>             // call the template load event.
>             var function_name =  'template_'+ template_name
> +'_onload';
>             eval(function_name + '();' );
> As an aside I did, previous to this solution, try to combine the page
> HTML and inline Javascript and do a single update.
> container.update(new_content);
> however my _onload functions would not be registered in the browser
> causing the "call the template load event" part above to fail, dispite
> Prototype docs saying that Update evals inline scripts, well it does
> but the functions would not register.
> So either a solution to the first or an explination of the second
> method would be most appretiated.
> Thanks heaps every one.
> DaveC
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 

Reply via email to