www.webdeveloper.com
Results 1 to 5 of 5

Thread: writing code into popups

  1. #1
    Join Date
    Oct 2012
    Posts
    10

    Question writing code into popups

    hi,

    im trying to open a Javascript window and write content into it without having to load another page.

    this is my script so far,

    HTML Code:
    <head>
    <title>popups javascript</title>
    <script type=text/javascript>
    function popitup2() {
    	newwindow2=window.open('','name','height=200,width=150');
    	var tmp = newwindow2.document;
    	tmp.write('<html><head><title>popup</title>');
    	tmp.write('<script type=text/javascript>');
        tmp.write('var d=new Date(); document.write(d.getHours()+":"+d.getMinutes());');
    	tmp.write('</script></head><body><p>this is once again a popup.</p>');
    	tmp.write('</body></html>');
    	tmp.close();
    }
    
    </script></head>
    
    <body>
    <form>
    <input type="button" onClick="popitup2()" value="POP!">
    </form>
    <p onClick="popitup2()">CLICK ME TOO!</p></body>
    i dont know what is wrong?

    and

    iam wondering if this is the better way to do it[prev. content: only few lines]. it's also possible to do it in easier way, please share

    thanks

  2. #2
    Join Date
    Jul 2008
    Location
    urbana, il
    Posts
    2,787
    popups take a while to "boot", during which the DOM has not been built.

    maybe something like this?
    Code:
    function popitup2() {
    	newwindow2=window.open('','name','height=200,width=150');
    
        newwindow2.onload=function(){
    
    	var tmp = newwindow2.document;
    	tmp.write('<html><head><title>popup</title>');
    	tmp.write('<script type=text/javascript>');
        tmp.write('var d=new Date(); document.write(d.getHours()+":"+d.getMinutes());');
    	tmp.write('</script></head><body><p>this is once again a popup.</p>');
    	tmp.write('</body></html>');
    	tmp.close();
    
     }
    
    }

  3. #3
    Join Date
    Oct 2012
    Posts
    9
    Random guess, but this might be the problem

    Code:
    	tmp.write('</script></head><body><p>this is once again a popup.</p>');
    I think most browsers won't allow unescaped </script> tags even in JS strings.
    Try escaping the slash, i.e.

    Code:
    	tmp.write('<\/script></head><body><p>this is once again a popup.</p>');

  4. #4
    Join Date
    Oct 2012
    Posts
    10
    popups take a while to "boot", during which the DOM has not been built.
    thanks for reply and explanation

  5. #5
    Join Date
    Oct 2012
    Posts
    10

    resolved

    Quote Originally Posted by bundat View Post
    Random guess, but this might be the problem

    Code:
    	tmp.write('</script></head><body><p>this is once again a popup.</p>');
    I think most browsers won't allow unescaped </script> tags even in JS strings.
    Try escaping the slash, i.e.

    Code:
    	tmp.write('<\/script></head><body><p>this is once again a popup.</p>');

    yes. its working

    but , Popup don't present content only a blank screen...

    so, i try this

    HTML Code:
    <script type=text/javascript>
    function popitup2() {
    	var tmp='<html><head><title>popup</title>';
    	tmp+='<script type=text/javascript>';
        tmp+='var d=new Date(); document.write(d.getHours()+":"+d.getMinutes());';
    	tmp+='<\/script></head><body><p>this is once again a popup.</p>';
    	tmp+='</body></html>';
    	
    	var newwindow2=window.open('','name','height=200,width=150');
    
        newwindow2.document.write(tmp);
    
     }
    </script>
    </head>
    
    <body>
    <form>
    <input type="button" onClick="popitup2()" value="POP!">
    </form>
    <p onClick="popitup2()">CLICK ME TOO!</p>
    
    </body>

    thanks alot

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Tags for this Thread

Posting Permissions

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



Recent Articles