Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New Coder
    Join Date
    Mar 2003
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Popup script that isn't actually another HTML file

    Hi, I'm pretty certain I've seen this done before, but I don't know if it was just HTML, or JavaScript, or what (but I assume it was a javascript, so I'm putting it in here)... Is it possible to make a link on the HTML page, so that when you click it, a popup comes up with text and scripts and everything in it... except that all the text and scripting in that popup is ACTUALLY in the original HTML file.

  • #2
    Regular Coder
    Join Date
    Mar 2003
    Posts
    176
    Thanks
    0
    Thanked 0 Times in 0 Posts
    A simple demo...
    (EDIT: fixed typos and included document.close())
    Code:
    <html>
    <head>
    <title>Demo</title>
    <script language="jav&#97;script" type="text/jav&#97;script">
    <!--
    
    var myPopup
    function openPopup(){
    
    myPopup=window.open('','myPop','width=400,height=400')
    myPopup.document.write("<html><head><title>Popup</title>")
    myPopup.document.write("<body><h1>Hello</h1></body>")
    myPopup.document.write("</html>")
    myPopup.document.close()
    }
    //-->
    </script>
    </head>
    <body>
    <a href="jav&#97;script: openPopup()">Open popup window</a>
    </body>
    </html>
    It can get a bit trickier than this but it will give you the idea.
    Last edited by HairyTeeth; 04-01-2003 at 08:25 PM.

  • #3
    New Coder
    Join Date
    Mar 2003
    Posts
    11
    Thanks
    0
    Thanked 0 Times in 0 Posts
    That script didn't work. It's probably one of those things where it's just a typo spelling error somewhere. I took out the extra "a" in "javaascript", but that still didn't fix it, or there's another typo somewhere.

    :EDIT:
    I found the other error, down near the bottom it said "java script". I took out the space, and it now works.

    Thanks a ton for the script!!!
    Last edited by Erica_qt; 04-01-2003 at 02:52 PM.

  • #4
    Senior Coder
    Join Date
    Aug 2002
    Posts
    3,467
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Missing one crucial step

    myPopup=window.open('','myPop','width=400,height=400')
    myPopup.document.write("<html><head><title>Popup</title>")
    myPopup.document.write("<body><h1>Hello</h1></body>")
    myPopup.document.write("</html>")
    myPopup.document.close();

    That closes the output stream to the new window and allows it to render
    My Site | fValidate | My Brainbench | MSDN | Gecko | xBrowser DOM | PHP | Ars | PVP
    “Minds are like parachutes. They don't work unless they are open”
    “Maturity is simply knowing when to not be immature”

  • #5
    Master Coder
    Join Date
    Feb 2003
    Location
    Umeå, Sweden
    Posts
    5,575
    Thanks
    0
    Thanked 83 Times in 74 Posts
    Beetle - actually, it renders without document.close. document.close only tells the browser to close the input stream, by what it knows that there will be no more content for it to render, and thus the load even can be triggered.
    liorean <[lio@wg]>
    Articles: RegEx evolt wsabstract , Named Arguments
    Useful Threads: JavaScript Docs & Refs, FAQ - HTML & CSS Docs, FAQ - XML Doc & Refs
    Moz: JavaScript DOM Interfaces MSDN: JScript DHTML KDE: KJS KHTML Opera: Standards

  • #6
    Regular Coder
    Join Date
    Nov 2002
    Posts
    596
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Alternative:

    <html>
    <head>
    <title>Demo</title>
    <script language="javascript" type="text/javascript">
    <!--

    var myPopup = null;
    var HTML;
    function openPopup(){
    HTML = '';
    HTML += "<html><head><title>Popup</title>";
    HTML += "<body onload=setTimeout('self.close()',2000)><h1>Hello</h1></body>";
    HTML += "</html>";
    myPopup=window.open('javascript&#58;opener.HTML','myPop','width=400,height=400');
    }

    //-->
    </script>
    </head>
    <body>
    <a href="javascript&#58;void openPopup()">Open popup window</a>
    </body>
    </html>

    I've found this to be much more reliable, since the new document is written to synchronously (by .open()), avoiding the 'access denied' errors that plague IE when you do it on-the-fly.


  •  

    Posting Permissions

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