SitePoint Sponsor

User Tag List

Results 1 to 10 of 10
  1. #1
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    document.write problem

    hi!
    i have a problem with inserting javascript function into document.write sentence!
    example:
    document.write('<script type="javascript" src="js/test.js"></script>');
    and that wont work!!!
    can someone explain me how to insert a function into document.write?
    thanx in advance!

  2. #2
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    I believe it is because your write function is wrong - it should be writeln (notice the "ln")

    Code:
    document.writeln('<script type="javascript" src="js/test.js"></script>');
    Nick . all that we see or seem, is but a dream within a dream
    Show someone you care, send them a virtual flower.
    Good deals on men's watches

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    thanx a lot but i tryed with document.writeln and it wont work too!
    it gives me some error like infinite string at the start of the </script> at the caracter 27 cca!!!
    maybe ive to put into some prefix like +function+ or something like that?
    some other sugestions?
    thanx in advance!!!

  4. #4
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm I don't know, I even tried replace the < and > with &rt; and &gt;
    Nick . all that we see or seem, is but a dream within a dream
    Show someone you care, send them a virtual flower.
    Good deals on men's watches

  5. #5
    SitePoint Addict
    Join Date
    May 2003
    Location
    The Netherlands
    Posts
    391
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hi reminder,

    It's not type="javascript" but type="text/javascript". You should also add the attribute language with a value of "JavaScript", although it probably works without it also.

    Code:
    document.writeln('<script type="text/javascript" language="JavaScript" src="js/test.js"></script>');
    I hope it helped.

  6. #6
    SitePoint Addict
    Join Date
    May 2004
    Location
    Europe
    Posts
    216
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Also, replace </script> with <\/script>

  7. #7
    SitePoint Wizard
    Join Date
    Jul 2003
    Location
    Kent
    Posts
    1,921
    Mentioned
    1 Post(s)
    Tagged
    0 Thread(s)
    ?? and perhaps the same for text/javascript and js/test.js
    use text\/javascript
    and js\/test.js

    just a wild guess

  8. #8
    masquerading Nick's Avatar
    Join Date
    Jun 2003
    Location
    East Coast
    Posts
    2,215
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Hmm I tried out all combinations of the above on my machine and none of them worked.
    Nick . all that we see or seem, is but a dream within a dream
    Show someone you care, send them a virtual flower.
    Good deals on men's watches

  9. #9
    &#083;itePoint Aficionado JVLB's Avatar
    Join Date
    Jan 2002
    Location
    N 44 56.537' W 123 3.683'
    Posts
    1,127
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    When inserting script tags into a document through document.write(), you should break the tag up so as not to confuse the interpreter, like this:

    document.write('<scr'+'ipt>');

    Additionally, as has been suggested, any closing HTML tags should have the forward slash escaped by preceeding it with a back slash, as in:

    document.write('<style type="text/css"><\/style>');

    The latter is recommended because the interpreter is supposed to expect the next actual closing tag to be the closing tag for the script block. It should be noted that IE Win usually overlooks the lack of these niceities, so if that is the browser which is giving you trouble, the problem is probably elsewhere.

    The language="JavaScript" attribute has actually been deprecated and will not valid in the stricter !DOCTYPE declarations. Most all browsers, however, will not complain.

  10. #10
    SitePoint Wizard
    Join Date
    Mar 2004
    Posts
    1,647
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    this one work for certainly!!!
    Code:
    document.writeln('<script type="text/javascript" language="JavaScript" src="js/test.js"><\/script>');
    thanx a lot guys uve helped me good!!!


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •