|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
#1
|
|||
|
|||
|
Hi,
I need to generate a new document that will contain javascripting with the document.write method I create a string : tmp = ""; tmp += "<HTML>......"; tmp += "....<SCRIPT>"; tmp += "............"; tmp += "............"; tmp += "...</SCRIPT>"; tmp += "...</HTML>"; And when I do the instruction : document.open(); document.write(tmp); document.close(); I crashes when the browser evaluates the </script> in the tmp string !!! Does anybody has an idea of the way to do it ??? Thanks for any help. 2ki. |
|
#2
|
|||
|
|||
|
I don't know what you have placed between the <SCRIPT>..</SCRIPT> tags, but it could be that there are certain characters (like ", etc.) which cause it.
You should 'escape' these characters with an , e.g. '"' (to display " itself). Check this or else let us know what is between those tags. Good christmas! |
|
#3
|
|||
|
|||
|
I would suggest putting the javascript between your script tags as a function in the same file you are doing your document.write() from.
then the <body> can have an onload event that calls this function. ex. function initNewHTML(){ // your script here } function CreateNewHtml(){ var str=""; str +="<html><body onload='initNewHTML()'></body></html>" document.open(); document.write(str); docuent.close(); } |
|
#4
|
|||
|
|||
|
I agree to the previous posts (about escaping special characters like /) but there is another thing to consider:
if you do a document.write in the same document where the var is you want to write it might well be that you kill the whole skript since the browser starts a whole new document. This will kill the skript and the var. |
![]() |
| Viewing: Dev Shed Forums > Web Design > HTML Programming > error using document.write("........"); |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|
|
|