Click to See Complete Forum and Search --> : reference external js in document.write()


epowder
10-17-2003, 04:35 AM
hi,

i don't know exactly what the problem is here, i think it's the reference i'm writing to an external js file.

I'm opening a new window for writing in it and i would like the window to have functions, so i'm using an external js file.

the writing page :

<html>
<head>
<title>Work</title>
<script language="JavaScript" >
function writePage(){
var newWin = window.open('','');
newWin.document.write("<html><head><scrip"+"t type=\"text\/javascript\" Language=\"JavaScript\" src=\"functions.js\"></scrip"+"t></head>");
newWin.document.write("<body bgcolor=\"#000000\" topmargin=\"0\" leftmargin=\"0\" vlink=\"#00FFFF\">");
newWin.document.write("<p onclick=\"justSome();\"><font color=\"white\">clicking this will call a function in the external js file, just to see that it's working</font><br><br></p>");
newWin.document.write("</body></html>");
newWin.document.close();
}
</script>
</head>
<body onLoad="writePage();">
</body>
</html>



functions.js has just one function for now:


function justSome(){
alert("some alert message");
}



This is working fine locally. It's working fine remotely when using Mozilla, but Internet Explorer hangs on it(at least IEv6).
You can see/test it here http://users.pandora.be/epowder/i.html
Can anyone tell me where the problem is ?
Is it the way i open the window ?
Is it the way i'm writing in it ?
Does anyone else have an alternate way for doing these things ?


Been searching on this for hours :(

thanks a lot

epowder

Mr J
10-18-2003, 05:05 AM
Try putting a backslash before the forward slash in the closing document.write script tag, see if that cures it.


<html>
<head>
<title>Work</title>
<script language="JavaScript" >
function writePage(){
var newWin = window.open('','');
newWin.document.write("<html><head><scrip"+"t type=\"text/javascript\" Language=\"JavaScript\" src=\"functions.js\"><\ /scrip"+"t></head>");
newWin.document.write("<body bgcolor=\"#000000\" topmargin=\"0\" leftmargin=\"0\" vlink=\"#00FFFF\">");
newWin.document.write("<p onclick=\"justSome();\"><font color=\"white\">clicking this will call a function in the external js file, just to see that it's working</font><br><br></p>");
newWin.document.write("</body></html>");
newWin.document.close();
}
</script>
</head>
<body onLoad="writePage();">
</body>
</html>

epowder
10-18-2003, 05:15 AM
same thing, works locally, not remotely

but can you tell me why you would do that ?


thanks

Khalid Ali
10-18-2003, 07:59 AM
Mr J was on right track.If you write full html using JS then you will need to escape the forward slash

the function below will work

function writePage(){

var newWin = window.open('','');
newWin.document.open();
newWin.document.write("<html><head><scrip"+"t type=\"text/javascript\" Language=\"JavaScript\" src=\"functions.js\"><\/scrip"+"t><\/head>");
newWin.document.write("<body bgcolor=\"#000000\" topmargin=\"0\" leftmargin=\"0\" vlink=\"#00FFFF\">");
newWin.document.write("<p onclick=\"justSome();\"><font color=\"white\">clicking this will call a function in the external js file, just to see that it's working</font><br><br></p>");
newWin.document.write("<\/body><\/html>");
newWin.document.close();

}

epowder
10-18-2003, 08:08 AM
thanks for the effort guys,

but it's still not working on IE6 (it's supposed to give a black page with one line of white text)

http://users.pandora.be/epowder/notworking.html


sorry about the other thread, was ment to strip it down a bit

regards, epowder

Khalid Ali
10-18-2003, 08:40 AM
solution I posted above works perfectly,
make sure you implement it correctly.

Here is a link where I have it running

http://68.145.35.86/temp/WinOpenIETest.html

epowder
10-18-2003, 08:44 AM
my Internet Explorer hangs on that link

what exact version are you using ?
mine is 6.0.2600.000


something strange is going on

edit: tried your link on 3 different machines. 2 have IE6, 1 has IE 5.0.014. They all hang. They keep telling me it's downloading functions.js

Mr J
10-18-2003, 09:20 AM
Unfortunately my browser hung on that link as well I have IE 5.5.

This is very strange

Khalid Ali
10-18-2003, 09:35 AM
strange check out again,I found out that first time it was opening the window second time it would hang,anyways,I have tweeked to code a bit and it seems to work fine now,I tested about 5 times open anc close window.

IE6 .0.2800.1106
SP1
win2k pro

Mr J
10-18-2003, 09:55 AM
It appears to be alright now Khalid, giving the window a name appears to have done the trick

epowder
10-18-2003, 10:06 AM
yes indeed, the link is working time after time, although i recall giving it a name one the many times of trying

but now another problem occurs:
when i use your code locally or on my webspace, the justSome() function on the text is not executing.
Line 1: Object expected

has one of you tried that ?

see http://users.pandora.be/epowder/WinOpenIETest.html

edit:
or try this one:
http://users.pandora.be/epowder/another.html
because i found somewhere that <p> does not have onClick on all browsers

this main, writing page has the same image with onClick to demonstrate the justSome() function

epowder
10-18-2003, 10:51 AM
ok, nevermind :D

you had you js called function
mine was functions with trailing s


so what was the initial problem ? tried some stuff and it seems it was because i was using multiple writes.
Putting it all in one write solved it


thanks for the help guys !!appreciated!!

epowder

Khalid Ali
10-18-2003, 10:56 AM
you are welcome