List Info

Thread: Re: add javascript on the fly




Re: add javascript on the fly
country flaguser name
United States
2007-03-10 17:38:52
what is the reason for the second script

what is it doing

standleydj

On Mar 10, 3:33 am, "ojvm"
<yomerosoy2005-foros...yahoo.com> wrote:
> Hi every body. as my post says, i want to add
javascript to my page on
> the fly. for example
>
> page1.html
>
> <html>
> <head>
> <script
type='text/javascript'src='controlador.js'></script>
;
>
> <title>...</title>
> </head>
> <body>
> .....
> </body>
> </html>
>
> now when the page has been loaded, acording some user's
actions i'd
> like to add a new script, like this.
>
> page1.html
>
> <html>
> <head>
> <script
type='text/javascript'src='controlador.js'></script>
;
> <script
type='text/javascript'src='new-file-just-added.js'></s
cript>
>
> <title>...</title>
> </head>
> <body>
> .....
> </body>
> </html>
>
> right now i'm doing this.
>
> document.write("<script
type='text/javascript'src='new-file-just-
> added.js''></script>");
>
> obviusly this is not working properly, because, i
think, in that way
> all the content is erased.
>
> hope you can helpme. thanks


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "JavaScript Forum" group.
To post to this group, send email to
JavaScript-Informationgooglegroups.com
To unsubscribe from this group, send email to
JavaScript-Information-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/JavaScript-Information
?hl=en
-~----------~----~----~----~------~----~------~--~---


Re: add javascript on the fly
country flaguser name
United States
2007-03-18 21:50:02

You can do something like this:

<div id="scriptPlaceholder"></div>

and later when desired:

function includeScriptLater()
{
// you may have to break up the included script tags as
there may be
some security that prevents it from
// being executed - usually something like
"<scri" + "pt type='text/
javascr" + "ipt' src=' .....
document.getElementByID('scriptPlaceholder').innerHTML =
"<script
type='text/javascript'src='new-file-just-
added.js''></script>";
}

You could also use insertAdjacentHtml add html to the end
(or anywhere
within) the document while it is already loaded.

The reason Standleydj asked is most likely the fact that
this is
likely bad practice, as it implies that what you are loading
is not
known.  However, if you know which script to include, then
why not
just include all scripts.  Most likely there is a more
elegant way of
achieving what you are ultimately trying to do, but you have
not
revealed the ultimate goal.

Hope this helps!
Cheers

On Mar 12, 12:11 pm, "ojvm"
<yomerosoy2005-foros...yahoo.com> wrote:
> Well as i said in my first post, i'd like to add some
scripts on the
> fly, acording the user's actions. so instead of loading
all the
> scripts at the same time, the scripts would be loaded
when they are
> needed. and the second script is just an example.
>
> On 10 mar, 17:38, "Standleydj"
<standle...gmail.com> wrote:
>
>
>
> > what is the reason for the second script
>
> > what is it doing
>
> > standleydj
>
> > On Mar 10, 3:33 am, "ojvm"
<yomerosoy2005-foros...yahoo.com> wrote:
>
> > > Hi every body. as my post says, i want to add
javascript to my page on
> > > the fly. for example
>
> > > page1.html
>
> > > <html>
> > > <head>
> > > <script
type='text/javascript'src='controlador.js'></script>
;
>
> > > <title>...</title>
> > > </head>
> > > <body>
> > > .....
> > > </body>
> > > </html>
>
> > > now when the page has been loaded, acording
some user's actions i'd
> > > like to add a new script, like this.
>
> > > page1.html
>
> > > <html>
> > > <head>
> > > <script
type='text/javascript'src='controlador.js'></script>
;
> > > <script
type='text/javascript'src='new-file-just-added.js'></s
cript>
>
> > > <title>...</title>
> > > </head>
> > > <body>
> > > .....
> > > </body>
> > > </html>
>
> > > right now i'm doing this.
>
> > > document.write("<script
type='text/javascript'src='new-file-just-
> > > added.js''></script>");
>
> > > obviusly this is not working properly,
because, i think, in that way
> > > all the content is erased.
>
> > > hope you can helpme. thanks- Hide quoted text
-
>
> - Show quoted text -


--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the
Google Groups "JavaScript Forum" group.
To post to this group, send email to
JavaScript-Informationgooglegroups.com
To unsubscribe from this group, send email to
JavaScript-Information-unsubscribegooglegroups.com
For more options, visit this group at http://groups.google.com/group/JavaScript-Information
?hl=en
-~----------~----~----~----~------~----~------~--~---


[1-2]

about | contact  Other archives ( Real Estate discussion Medical topics )