Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

can't write "<SCRIPT....." to new window

Status
Not open for further replies.

platypus55

Programmer
Aug 15, 1999
32
0
0
US
I'm opening a new window as "", and writing a page to it. Some of the content is dependent on user input but the header<br>
is always the same, so I can just say:<br>
<br>
newWindow.document.write("&lt;HTML&gt;\n"); etc., etc.<br>
<br>
all fine until I try to say<br>
<br>
newWindow.document.write("&lt;SCRIPT LANGUAGE='JavaScript'&gt;\n");<br>
<br>
it steadfastely skips over all the Javascript, then resumes<br>
writing what I ask it to when the script part is over.<br>
<br>
This is straight line code, folks. Why will it copy some<br>
text and not other text? Obviously the page with the javascript isn't much good unless the javascript is in it!!
 
Did you check for a closing tag, and make sure all of your other tags are in proper order? also. which browser are you using?
 
When your browser is performing a document.write operation, it is already in Javascript mode, so you don't need the &lt;SCRIPT LANGUAGE='JavaScript'&gt;\n reference. Also, your Javascript needs to be OUTSIDE the " text delimiter. Try:<br>
<br>
newWindow.document.write("&lt;WHATEVER HTML&gt;etc..." + whateverjavascript + "&lt;MORE HTML&gt;etc...");<br>
<br>
Basically, since your browser is already performing a Javascript action, let it perform the new Javascript directly.
 
Thanks for the replies. Wow. I should clarify. I am trying<br>
to put a Javascript FUNCTION in the window I am writing. Eventually, the user will cart off the source and put it elsewhere independent of me, so he can't, say, invoke a javascript function<br>
from the opener window. And I don't want the script to run at this time, I need it to be in the file for later. <br>
<br>
All my tags are in order, because the javascript function works and has been tested.<br>
<br>
I am using Netscape 4.5 on a Mac<br>
<br>
Here is the code I am trying to write:<br>
d = newwindow.document<br>
res = "&lt;!DOCTYPE HTML PUBLIC '-//W3C//DTD HTML 3.2//EN'&gt;\n";<br>
res += "&lt;HTML&gt;\n";<br>
res += "&lt;HEAD&gt;\n";<br>
res += "&lt;META name = 'description' content = 'JavaScript Interactive Crossword Puzzle '&gt;\n";<br>
res += "&lt;META name = 'keywords' content = 'crossword xword puzzle word puzzles interactive Javascript'&gt;\n";<br>
<br>
d.write(res);<br>
res = "&lt;TITLE&gt;Interactive Crossword Puzzle&lt;/TITLE&gt;\n";<br>
res += '&lt;script LANGUAGE="JavaScript"&gt;';<br>
res += "&lt;" + "!--\n"<br>
res += "function checkChar(rightChar,guessChar,i) {\n";<br>
res += " var testChar=guessChar.toLowerCase();\n";<br>
res += " var msg='*';\n";<br>
res += " if(testChar != rightChar) {\n";<br>
res += " document.CrossWords.elements.value=msg\n";<br>
res += "}\n";<br>
d.write(res);<br>
res = " else\n"; <br>
res += " return true;\n";<br>
res += "}\n";<br>
res += "--" + "&gt;\n";<br>
res += "&lt;" + "/" + "SCRIPT&gt;\n";<br>
res += "&lt;/HEAD&gt;\n";<br>
d.write(res);
 
hmmm....if you are already using document.write instead of document.writeline then you can do the following:<br>
<br>
d.write(res);<br>
res = "&lt;TITLE&gt;Interactive Crossword Puzzle&lt;/TITLE&gt;\n";<br>
res += '&lt;script';<br>
d.write(res);<br>
res = ' LANGUAGE="JavaScript"&gt;';<br>
res += "&lt;" + "!--";<br>
res += "function checkChar(rightChar,guessChar,i) {\n";<br>
res += " var testChar=guessChar.toLowerCase();\n";<br>
res += " var msg='*';\n";<br>
res += " if(testChar != rightChar) {\n";<br>
res += " document.CrossWords.elements.value=msg\n";<br>
res += "}\n";<br>
d.write(res);<br>
res = " else\n"; <br>
res += " return true;\n";<br>
res += "}\n";<br>
res += "--" + "&gt;\n";<br>
res += "&lt;/";<br>
d.write(res);<br>
res = "SCRIPT&gt;\n";<br>
res += "&lt;/HEAD&gt;\n";<br>
d.write(res);<br>
<br>
This *should* break up the JS determining tags being written to the 2nd page enough that the JS in the "mother" page would'nt recognize them as such.....please let us know how this goes for you.<br>
<br>
<br>
-Robherc<br>

 
I tried breaking up the script tags as you suggested, including inserting the d.write command between the broken points but the document source still doesn't have the<br>
javascript code in it. <br>
<br>
This is why I HATE Javascript. I thought I might try having<br>
everything in a textarea (see new thread I started), and that isn't working either. <br>
<br>
<br>
Aaaauuuuugh!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top