By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
457,704 Members | 937 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 457,704 IT Pros & Developers. It's quick & easy.

javascript include in a javascript shows a white screen

P: 29

I have following files:


in test.html i have 2 includes:
- style1.css
- script1.JS

in style1.css there's an @import of style2.css (works fine)

in script1.JS, I tried to include script2.JS as following:
document.write('<script type="text/javascript" src="script2.js" charset="UTF-8"></scr' + 'ipt>');

When I launch the html page, i have 2 situations:
only the half of the html is loaded and de scrollbar is totally locked.
the moment i refresh the page, i get a white page.
when i look at the script, I only see:
<script type="text/javascript" src="script2.js" charset="UTF-8"></script>

When I include the script2.js manually in html, it works perfectly fine!

Is there any workaround to solve this problem?

Thank you so much in advance!

Oct 28 '08 #1
Share this Question
Share on Google+
9 Replies

P: 29
a small update:

When I include the javascript directly in the html, the page is shown.
but what's not applied is following:
the style2.css (which is an import of style1.css)

the moment i refresh the page, the style changes are applied.
when i open a new tab (mozilla or IE) all styles are applied correctly.
only when i open a new browser window, i'll get the same problem again.

at first i thought i had a javascript problem, but apparantly i have also a css problem...

some additional info about the css's:
style1.css is an empty file with 2 lines:

@import style2.css
@import style3.css.asp

(this asp file only writes css if the user is set as a touchscreen user)
Oct 28 '08 #2

Expert Mod 15k+
P: 16,027
Could you attach the files or post a link if it's online?
Oct 29 '08 #3

P: 93
Can you please tell us that are you writing these files in the server side language like php ,asp,jsp or directly the html page.

What is you need?Do you want to include only one js file and want to acess the other one from the first one is it so?
Oct 30 '08 #4

P: 29
I use ASP.

I found a solution for the css.
normally i should press F5 before he shows me the 2nd css.

well, i made a function which attach following to the css link:

styletouch.css?457=964 (the numbers are random, so it's not cached)

I only need to add the javascript script:

Document.Write('<script type="text/javascript" src="../js/script.js" charset="UTF-8"></scr' + 'ipt>');

This line is included in a javascript already included in the file.
when i run it, internet explorer seems to freeze.

The files are on intranet, so i can't show them
Oct 30 '08 #5

Expert Mod 15k+
P: 16,027
You can either attach the files or at least post the relevant parts of the file for testing.

Note that JavaScript is case-sensitive, so it should be document.write(...), not Document.Write(...).
Oct 30 '08 #6

P: 93
That is what you had done which could be done by including this in a html file.If you are writing like this you have to be more cautious .Suppose you need to call a function which is inside this or you need only the reference of the js file where you have kept some important function as done in prototype.Then you have to call the function where it is written to include this js file as you specified by document.write method.Also document.write can cause some more problems it can kill the contents of the page dynamically.

And suppose what will happen if a person reload or refresh your page and use that function which is dependant on the js file which is going to be included dynamically.So it is better practice to write smart code which cant fail in any case.
Oct 30 '08 #7

Expert Mod 15k+
P: 16,027
Note that to avoid problems with document.write, you can load the script dynamically after the page has loaded using something like the following:
Expand|Select|Wrap|Line Numbers
  1. var script = document.createElement("script");
  2. script.type = "text/javascript";
  3. script.src = "../js/script.js";
  4. document.getElementsByTagName("head")[0].appendChild(script);
Oct 30 '08 #8

P: 93
Yes the solution provided by the acoder is much fine then using the document.write.So please use it insted of document.write You can also use inner.html for this purpose this will serve you better.
Oct 31 '08 #9

P: 29
thank you so much for the superb tip.

yet, I use following init script:

function Initialize () {
var script = document.createElement("script");
script.type = "text/javascript";
script.src = "../js/vkb/keyboard.js";


Yet, my javascript is not loaded.
only if i put an alert command at the end.
for example:

alert ("test");

Then my script is ok.
I have some knowledge about javascript, but this part i don't understand.
How should I fix this?

in the html I use:

<body onload="Initialize()";>
Oct 31 '08 #10

Post your reply

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