wwarby
2008-Jul-05 10:08 UTC
Prototype: Load <script> with src attribute using insert() at runtime
Hi all, Using the latest version of Prototype, I''m trying to dynamically load JavaScripts at runtime on demand, into the head or body tags (I don''t actually care which). The insert() method just seems to do nothing when I specify a script tag containing a src attribute: $$(''body'')[0].insert(''<script type="text/javascript" src="dynamic.js"></script>''); However, if I omit the src tag, instead using in-line JavaScript inside the tag, it loads correctly: $$(''body'')[0].insert(''<script type="text/javascript">alert("foo");</ script>''); Is this some kind of browser security feature or a bug, or am I just doing something goofy? I could get the contents of the file using a server script but that would be a very dirty solution that I''d like to avoid if possible. Grateful for any advice received. --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---
wwarby
2008-Jul-05 11:21 UTC
Re: Prototype: Load <script> with src attribute using insert() at runtime
Apologies, I see this question has been posted several times before. I have solved the problem using document.createElement to manally create the script element and that seems to work fine ;) On Jul 5, 11:08 am, wwarby <m...-j5djf4o5K3vQT0dZR+AlfA@public.gmane.org> wrote:> Hi all, > > Using the latest version of Prototype, I''m trying to dynamically load > JavaScripts at runtime on demand, into the head or body tags (I don''t > actually care which). The insert() method just seems to do nothing > when I specify a script tag containing a src attribute: > > $$(''body'')[0].insert(''<script type="text/javascript" > src="dynamic.js"></script>''); > > However, if I omit the src tag, instead using in-line JavaScript > inside the tag, it loads correctly: > > $$(''body'')[0].insert(''<script type="text/javascript">alert("foo");</ > script>''); > > Is this some kind of browser security feature or a bug, or am I just > doing something goofy? I could get the contents of the file using a > server script but that would be a very dirty solution that I''d like to > avoid if possible. > > Grateful for any advice received.--~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Ruby on Rails: Spinoffs" group. To post to this group, send email to rubyonrails-spinoffs-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org To unsubscribe from this group, send email to rubyonrails-spinoffs-unsubscribe-/JYPxA39Uh5TLH3MbocFFw@public.gmane.org For more options, visit this group at http://groups.google.com/group/rubyonrails-spinoffs?hl=en -~----------~----~----~----~------~----~------~--~---