472,111 Members | 2,047 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,111 software developers and data experts.

How to import a line with js

manuelgk
Hello!, do you know how I can add a HTML line with a .js file into the <head> tags in a HTML document? This is because I want to put maybe a <title> tags or a <script> tag. Would you like to give me some examples?
Thanks a lot.
Dec 3 '07 #1
7 1283
acoder
16,027 Expert Mod 8TB
Can you give an example of something that you want to add and when? On body onload?
Dec 3 '07 #2
Can you give an example of something that you want to add and when? On body onload?
Mmm ok, for example I want to add a call line to a script (<script src="file.js"...) when I load a HTML document. In other words add a script call before I load a page and when I load it, the new call script works. Is that clear?
Thanks
Dec 3 '07 #3
acoder
16,027 Expert Mod 8TB
Mmm ok, for example I want to add a call line to a script (<script src="file.js"...) when I load a HTML document. In other words add a script call before I load a page and when I load it, the new call script works. Is that clear?
Thanks
Put the script in the head and call the function(s) onload.

To run onload, use <body onload="function()"> or window.onload=nameoffunction;
Dec 4 '07 #4
Well, I should explain you better because I forgot somethings to mention.
The fact is, I have "1.html" where I have a link to "2.html". In "1.html " I have a script call (<script src=....js>...). This script, when I click the hyperlink, should add a script call between head tags in the "2.html". So, before the "2.html" loads, the .js file should add the line <script src=...js> to the "2.html" and when it loads, the new call script works. I read that it could be possible add title tags from a script so I suppose that it could be add anything between the head tags.
Kind regards
Dec 4 '07 #5
acoder
16,027 Expert Mod 8TB
The fact is, I have "1.html" where I have a link to "2.html". In "1.html " I have a script call (<script src=....js>...). This script, when I click the hyperlink, should add a script call between head tags in the "2.html". So, before the "2.html" loads, the .js file should add the line <script src=...js> to the "2.html" and when it loads, the new call script works. I read that it could be possible add title tags from a script so I suppose that it could be add anything between the head tags.
You can add to the page itself, so 1.html can add to its own head, but not to another file. You can add parameters to the URL which you can check with location.search (e.g. "?addfile=1"). If the parameter is set, add the script tag to the head, otherwise leave as is.
Dec 4 '07 #6
OK got it! thanks again.
Dec 11 '07 #7
acoder
16,027 Expert Mod 8TB
OK got it! thanks again.
No problem. Glad it helped.
Dec 12 '07 #8

Post your reply

Sign in to post your reply or Sign up for a free account.

Similar topics

reply views Thread by Stian Søiland | last post: by
reply views Thread by Vio | last post: by
5 posts views Thread by Steve Holden | last post: by
1 post views Thread by Learning Python | last post: by
79 posts views Thread by pinkfloydhomer | last post: by
16 posts views Thread by didier.doussaud | last post: by
2 posts views Thread by Bill Jackson | last post: by
10 posts views Thread by Thomas Guettler | last post: by
reply views Thread by leo001 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.