Opening a new html window using javascript

Discussion in 'Javascript' started by Michael Landberg, Feb 6, 2008.

  1. Hi

    I have a piece of code that has to open a new small window with some
    formatting text in it. If I run the code and the new windows opens the
    text is displayed without the formatting ( spaces, open lines between
    some text, etc.). But when I place an alert function like
    alert(newContent) I can see perfectly all the formatting that is in
    the text.

    Is there a variable I have to add in my code below to make sure that
    the new window is opened with the text formatting?


    newWindow =
    window.open('','','width=500,height=300,left=550,top=250",status=no,toolbar=no,scrollbars=yes ,
    menubar=no');

    // write HTML to new window document
    newWindow.document.write(newContent)


    Any help will be appreciated.

    Regards
     
    Michael Landberg, Feb 6, 2008
    #1
    1. Advertising

  2. Michael Landberg

    GArlington Guest

    On Feb 6, 8:28 am, Michael Landberg <> wrote:
    > Hi
    >
    > I have a piece of code that has to open a new small window with some
    > formatting text in it. If I run the code and the new windows opens the
    > text is displayed without the formatting ( spaces, open lines between
    > some text, etc.). But when I place an alert function like
    > alert(newContent) I can see perfectly all the formatting that is in
    > the text.
    >
    > Is there a variable I have to add in my code below to make sure that
    > the new window is opened with the text formatting?
    >
    > newWindow =
    > window.open('','','width=500,height=300,left=550,top=250",status=no,toolbar=no,scrollbars=yes ,
    > menubar=no');
    >
    > // write HTML to new window document
    > newWindow.document.write(newContent)
    >
    > Any help will be appreciated.
    >
    > Regards


    Check the docs about how document.write() works and you will see the
    error of your ways...
     
    GArlington, Feb 6, 2008
    #2
    1. Advertising

  3. On 6 feb, 11:52, GArlington <> wrote:
    > On Feb 6, 8:28 am, Michael Landberg <> wrote:
    >
    >
    >
    >
    >
    > > Hi

    >
    > > I have a piece of code that has to open a new small window with some
    > > formatting text in it. If I run the code and the new windows opens the
    > > text is displayed without the formatting ( spaces, open lines between
    > > some text, etc.). But when I place an alert function like
    > > alert(newContent) I can see perfectly all the formatting that is in
    > > the text.

    >
    > > Is there a variable I have to add in my code below to make sure that
    > > the new window is opened with the text formatting?

    >
    > > newWindow =
    > > window.open('','','width=500,height=300,left=550,top=250",status=no,toolbar­=no,scrollbars=yes ,
    > > menubar=no');

    >
    > > // write HTML to new window document
    > > newWindow.document.write(newContent)

    >
    > > Any help will be appreciated.

    >
    > > Regards

    >
    > Check the docs about how document.write() works and you will see the
    > error of your ways...- Tekst uit oorspronkelijk bericht niet weergeven -
    >
    > - Tekst uit oorspronkelijk bericht weergeven -


    Hi

    I don't understand what you mean. I have read online what this
    function does and saw examples of it. But I cannot find out what I am
    doing wrong. Which docs do you mean?
     
    Michael Landberg, Feb 6, 2008
    #3
  4. Michael Landberg

    GArlington Guest

    On Feb 6, 11:30 am, Michael Landberg <> wrote:
    > On 6 feb, 11:52, GArlington <> wrote:
    >
    >
    >
    > > On Feb 6, 8:28 am, Michael Landberg <> wrote:

    >
    > > > Hi

    >
    > > > I have a piece of code that has to open a new small window with some
    > > > formatting text in it. If I run the code and the new windows opens the
    > > > text is displayed without the formatting ( spaces, open lines between
    > > > some text, etc.). But when I place an alert function like
    > > > alert(newContent) I can see perfectly all the formatting that is in
    > > > the text.

    >
    > > > Is there a variable I have to add in my code below to make sure that
    > > > the new window is opened with the text formatting?

    >
    > > > newWindow =
    > > > window.open('','','width=500,height=300,left=550,top=250",status=no,toolbar­=no,scrollbars=yes ,
    > > > menubar=no');

    >
    > > > // write HTML to new window document
    > > > newWindow.document.write(newContent)

    >
    > > > Any help will be appreciated.

    >
    > > > Regards

    >
    > > Check the docs about how document.write() works and you will see the
    > > error of your ways...- Tekst uit oorspronkelijk bericht niet weergeven -

    >
    > > - Tekst uit oorspronkelijk bericht weergeven -

    >
    > Hi
    >
    > I don't understand what you mean. I have read online what this
    > function does and saw examples of it. But I cannot find out what I am
    > doing wrong. Which docs do you mean?


    document.write() OVERWRITES your complete document...
    So, you have to put ALL <html> <body> ... </body> </html> in your
    string in order for the document to be formatted as html, otherwise it
    is plain text...
     
    GArlington, Feb 6, 2008
    #4
    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. Patrick Olurotimi Ige

    Closing child window when opening a new Window

    Patrick Olurotimi Ige, Dec 14, 2004, in forum: ASP .Net
    Replies:
    2
    Views:
    462
    Patrick Olurotimi Ige
    Dec 14, 2004
  2. POL8985
    Replies:
    1
    Views:
    590
    Kevin Spencer
    Jan 31, 2005
  3. UJ
    Replies:
    2
    Views:
    7,599
    John Timney \(ASP.NET MVP\)
    Jun 27, 2005
  4. Clara
    Replies:
    6
    Views:
    619
    Clara
    Apr 25, 2005
  5. James Bondin

    Opening a new window using Javascript

    James Bondin, May 19, 2004, in forum: Javascript
    Replies:
    2
    Views:
    109
    Markus Ernst
    May 19, 2004
Loading...

Share This Page