#1
  1. No Profile Picture
    2ki
    Guest
    Devshed Newbie (0 - 499 posts)
    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. #2
  3. No Profile Picture
    PAV
    Guest
    Devshed Newbie (0 - 499 posts)
    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!
  4. #3
  5. No Profile Picture
    time2brew
    Guest
    Devshed Newbie (0 - 499 posts)
    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();
    }
  6. #4
  7. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 1999
    Location
    Muenster, NRW, Germany
    Posts
    17
    Rep Power
    0
    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.

IMN logo majestic logo threadwatch logo seochat tools logo