Javascript document.write question

Discussion in 'Javascript' started by Brett Baisley, Feb 17, 2004.

  1. Hello

    I have a block of html code that I want to run by calling a javascript
    function to print it. Its basically a table with menu items in it that is
    the same for many pages, and instead of copying/pasting everytime I change
    it, I figure this will be better, as I only change it once.

    The problem is, document.write doesn't handle multiple lines very well, so I
    was wondering what is the best way to do this? Maybe there is even a better
    way then javascript calls.

    Anything will be great! Thanks!

    Brett
    Brett Baisley, Feb 17, 2004
    #1
    1. Advertising

  2. mscir wrote:

    > [...] If you mean the data is not easy to read on the generated page,
    > insert \n where you want a newline to begin. Post your code for more
    > specific suggestions.
    >
    > http://www.devguru.com/Technologies/ecmascript/quickref/escaped_characters.html
    >
    > This code generates a new window with a table.
    >
    > <html>


    DOCTYPE declaration?

    > <title>CodeAve.com(JavaScript New Window within Previous Page)</title>
    > <body bgcolor="#FFFFFF">


    Text color?

    > <script language="JavaScript">


    "type" attribute?

    > <!--
    > function open_new_window() {
    > new_window =
    > open("","displayWindow","width=575,height=620,left=10,top=10\n");


    Wrong. The options (third) argument of window.open() must not
    contain newline. And _window._open() is recommended since there
    is document.open(). The function should be defined within
    the "head" element, not the "body" element, to be available always.

    > // open new document
    > new_window.document.open();
    >
    > // Text of the new document goes here
    > // Replace your " with ' or \" or document.write statements will fail
    >
    > new_window.document.write("<html>\n");


    See above.

    > new_window.document.write("<head>\n");
    > new_window.document.write("<meta http-equiv='Content-Type'
    > content='text/html; charset=windows-1252'>\n");

    ^^^^^^^^^^^^
    What about UAs that does not support this Windows character set?
    ISO-8859-1 is better.

    > new_window.document.write("<title>Table of Data</title>\n");

    ^^
    Not only that this is and creates invalid HTML for the most part, a
    smaller example would have sufficed. You have posted more than 200
    lines of garbage!


    PointedEars
    Thomas 'PointedEars' Lahn, Feb 24, 2004
    #2
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Spartanicus
    Replies:
    4
    Views:
    1,353
  2. nickolausp
    Replies:
    1
    Views:
    95
    Dom Leonard
    Jul 18, 2003
  3. John
    Replies:
    2
    Views:
    91
    Michael Winter
    Nov 16, 2004
  4. jullag
    Replies:
    20
    Views:
    294
    Frances
    Sep 22, 2005
  5. Frank Peterson
    Replies:
    9
    Views:
    219
    David Mark
    Jun 28, 2009
Loading...

Share This Page