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 9 of 9
  1. #1
    New Coder
    Join Date
    Apr 2009
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts

    document.writeln(' external html ')

    Hello, I made a javascript something like this...

    Code:
    function popup(url,title){
    	var pop = window.open("", "p0pup",....blahblah......);
    	p0pup.document.open();
    	p0pup.document.writeln('<html><head>.......//keeps going......</body></html>');
    	p0pup.document.close();
    }
    Basically it is a popup script. My question is that is there any way to reference to an external html using document.writeln? Instead of messy html codes within document.writeln, maybe something like this?

    p0pup.document.writeln('popup.html');

    Thanks for any tips.

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,898
    Thanks
    203
    Thanked 2,530 Times in 2,508 Posts
    No, document.write() can only output a literal string.

    document.writeln('popup.html'); outtputs the literal popup.html


    All advice is supplied packaged by intellectual weight, and not by volume. Contents may settle slightly in transit.

  • #3
    New Coder
    Join Date
    Apr 2009
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Uh I know that it won't work. I'm just wondering is there any way to do it to reference to an external html?

  • #4
    Senior Coder
    Join Date
    Jun 2002
    Posts
    1,404
    Thanks
    2
    Thanked 32 Times in 32 Posts
    window.open already features a way to "reference to an external html" ...

    window.open([url], [name], [features])

    Is that what you meant?

  • #5
    New Coder
    Join Date
    Apr 2009
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts
    so something like this?

    Code:
    <script language = "javascript">
    function popup(url,title){
    	var pop = window.open("popup.html", "p0pup",....blahblah......);
    	p0pup.document.open();
    	p0pup.document.close();
          	p0pup.focus();
    }
    </script>
    
    
    <input type="submit" value="submit" onClick="popup('url','title')"/>
    where popup.html lives in the same directory as in index.html

    However, all it pops up is a blank page...any idea why? (and...popup.html is not blank)
    Last edited by MrAtheist; 05-08-2009 at 07:29 PM.

  • #6
    Regular Coder
    Join Date
    Feb 2009
    Location
    Wheeling, IL
    Posts
    358
    Thanks
    5
    Thanked 62 Times in 60 Posts
    More like....

    Code:
    function popup(url,title){
        var pop =window.open("popup.html", "p0pup",....blahblah......);
        pop.focus();
    }
    In other words, you're trying to open p0pup while you're assigning window.open to a variable, called 'pop'.
    Last edited by Eldarrion; 05-08-2009 at 07:34 PM. Reason: Some wording was off... guess I need more coffee.
    The way to success is to assume that there are no impossible things. After all, if you think something is impossible, you will not even try to do it.

    How to ask smart questions?

  • Users who have thanked Eldarrion for this post:

    MrAtheist (05-08-2009)

  • #7
    New Coder
    Join Date
    Apr 2009
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts
    AHa thanks a bunch.

    I was going to report the bug just seconds ago. Now it pops up correctly.

    Thanks

  • #8
    New Coder
    Join Date
    Apr 2009
    Posts
    12
    Thanks
    2
    Thanked 0 Times in 0 Posts
    Uh but I got another question...

    Code:
    function popup(url,title){
        var pop = window.open("popup.html", "p0pup",....blahblah......);
        pop.focus();
    }
    See the 2 parameters 'url' and 'title'? They are going to be used later in popup.html. Is there any way to pass the parameters into popup.html?

    My guess...there aint a way to do it.

  • #9
    Regular Coder
    Join Date
    Feb 2009
    Location
    Wheeling, IL
    Posts
    358
    Thanks
    5
    Thanked 62 Times in 60 Posts
    Not sure about title... meaning not sure what you want to do with the title itself. Are we talking about calling the new window something, or do you want to alter the <title> element in the new window itself? Because I'm not sure if that can be done... url can be passed easily though... and I guess if you want to name the window itself something, you'd be doing it like so:

    Code:
    function popup(url,title){
        var pop = window.open(url, title,....blahblah......);
        pop.focus();
    }
    Make sure you pass url and title as strings when calling the function. I.e:

    Code:
    popup("popup.html","p0pup");
    See how that goes for you.
    The way to success is to assume that there are no impossible things. After all, if you think something is impossible, you will not even try to do it.

    How to ask smart questions?


  •  

    Posting Permissions

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