opening a new window with HTML code instead of file

Discussion in 'Javascript' started by laredotornado@zipmail.com, Aug 22, 2005.

  1. Guest

    Hello,
    I am searching for a cross-browser way (the most recent browsers
    are fine) to use javascript to open a new window even though I do not
    know the file I want to call. I do, however, know the HTML code I want
    output in the new window. It would look like

    <HTML>
    <HEAD><TITLE>Hello</TITLE>
    </HEAD>
    <BODY>
    Hello
    </BODY>
    </HTML>

    I understand I could put this text into a file and call that, but if
    there were a way to automatically populate the window with this code,
    prior to opening it, that would be the ideal.

    Thanks, - Dave
     
    , Aug 22, 2005
    #1
    1. Advertising

  2. Csaba Gabor Guest

    wrote:
    > Hello,
    > I am searching for a cross-browser way (the most recent browsers
    > are fine) to use javascript to open a new window even though I do not
    > know the file I want to call. I do, however, know the HTML code I want
    > output in the new window. It would look like


    var newWin = window.open("about:blank");
    newWin.document.open();
    newWin.document.write("<body>Some text</body>");
    newWin.document.close();
    newWin.document.title = "My favorite title";

    See also perhaps the recent discussion at:
    http://groups.google.co.uk/group/comp.lang.javascript/browse_frm/thread/18a60664279d6460/

    Csaba Gabor from Vienna
     
    Csaba Gabor, Aug 22, 2005
    #2
    1. Advertising

  3. Guest

    Thanks but sadly when I try this code on PC IE 6.0, I get a javascript
    error that says "Access Denied".

    Is there another way?

    - Dave
     
    , Aug 23, 2005
    #3
  4. |-|erc Guest

    <> wrote in
    > Thanks but sadly when I try this code on PC IE 6.0, I get a javascript
    > error that says "Access Denied".
    >
    > Is there another way?


    http://www.htmlgoodies.com/primers/jsp/article.php/3478241

    that any better?

    Herc
    --
    too intelligent
    See - you do get intelligent people on here! Kay. Well, there's you
    and me and Herc.... the rest are a bit sus though
    Dave Budd ~ UK Mensa founder
     
    |-|erc, Aug 23, 2005
    #4
  5. askMe Guest

    Csaba Gabor wrote:
    > wrote:
    > > Hello,
    > > I am searching for a cross-browser way (the most recent browsers
    > > are fine) to use javascript to open a new window even though I do not
    > > know the file I want to call. I do, however, know the HTML code I want
    > > output in the new window. It would look like

    >


    You would have to change the "about:blank" to a "/" or something to get
    the address bar to look right.

    function javascripttest()
    {
    var newWin = window.open("/");
    newWin.document.open();
    newWin.document.write("<body>My virtual web page <BR> is what you
    see!</body>");
    newWin.document.title = "My virtual title";
    newWin.document.close();
    return;
    }

    http://www.askblax.com

    > var newWin = window.open("about:blank");
    > newWin.document.open();
    > newWin.document.write("<body>Some text</body>");
    > newWin.document.close();
    > newWin.document.title = "My favorite title";
    >
    > See also perhaps the recent discussion at:
    > http://groups.google.co.uk/group/comp.lang.javascript/browse_frm/thread/18a60664279d6460/
    >
    > Csaba Gabor from Vienna
     
    askMe, Aug 23, 2005
    #5
  6. Csaba Gabor Guest

    wrote:
    > Thanks but sadly when I try this code on PC IE 6.0, I get a javascript
    > error that says "Access Denied".


    The popup blocker's stance is that it will only put up a popup on a
    user initiated action. That means things like clicking on buttons,
    etc. Unfortunately, IE/FF will not respond to popup attempts as a
    result of a keyboard listener (document.onkeyup = function() {...} )
    even though it's pretty clear that pressing a ctrl+key is not an
    accidental user action.

    The code below now includes a button you may press.
    Csaba Gabor


    <button onclick="dome()" accesskey=d><u>D</u>o me
    <script type='text/javascript'>
    function dome() {
    var newWin = window.open("about:blank");
    newWin.document.open();
    newWin.document.write("<body>Some text</body>");
    newWin.document.close();
    newWin.document.title = "My favorite title";
    }
    </script>
     
    Csaba Gabor, Aug 23, 2005
    #6
    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. UJ
    Replies:
    2
    Views:
    7,599
    John Timney \(ASP.NET MVP\)
    Jun 27, 2005
  3. Clara
    Replies:
    6
    Views:
    619
    Clara
    Apr 25, 2005
  4. Allan
    Replies:
    1
    Views:
    123
    Randy Webb
    Aug 6, 2004
  5. Replies:
    1
    Views:
    273
Loading...

Share This Page