SitePoint Sponsor

User Tag List

Results 1 to 2 of 2
  1. #1
    Confirmed Halfwit
    Join Date
    Oct 1999
    Location
    Vancouver, BC, Canada
    Posts
    983
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Possible to open new window or iframe and pass in HTML?

    Hello,

    I was just wondering two things about javascript:

    1. Is it possible to open a new window and pass in some HTML code? For example:
    Code:
    window.open('<HTML><HEAD></HEAD<BODY>Hello World</BODY></HTML>', 'test_window', 'width=400,height=200');
    2. Is it possible to pass in HTML code (using javascript) to an iframe window on the same page? I just want to update the text in the iframe. For example:
    Code:
    Some HTML code...
    <iframe name="STATUS" src="" </iframe>
    
    <script LANGUAGE=JavaScript>
    document.write.iframe.STATUS('<HTML><HEAD></HEAD<BODY>Hello World</BODY></HTML>');
    </script>
    Thanks!
    - A simple online WYSIWYG editor for HTML code snippets.
    - Managed Web Hosting - $3.95/month (resellers welcome)
    - Why pay more? $8.95 domains & $9.95 SSL certificates!

  2. #2
    Perl/Mason Guru Flawless_koder's Avatar
    Join Date
    Feb 2002
    Location
    Gatwick, UK
    Posts
    1,206
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    There are several methods i use to handle this.

    You *can* use the document.write method, but i prefer to be more dynamic.

    Are you familiar with the document.appendChild method?

    If you create the elements you want using a generic element creation funciton, you'll be able to add most things you want.

    i would normally add content by creating the holding elements.

    Code:
    <iframe></iframe>
    <script language="Javascript">
    
    var d=document.createElement('DIV');
    d.style.color='#660000';
    d.innerHTML='This is the first line of the text<br>';
    d.innerHTML+='And this is the second line';
    var s=document.createElement('SPAN');
    s.style.color='#000066';
    s.innerHTML='This is how to put secondary elements into a not yet created element!';
    d.appendChild(s);
    document.frames[0].appendChild(d);
    
    </script>
    You can, obviously, use the innerHTML and innerTEXT methods/properties to add directly to the iframe.

    It is perfection possibly to use this method on both opened windows and iframes alike, using the DOM references correctly.

    let me know if this doesn't answer your question, you don't undersand, or there is more i can do to help.

    Flawless
    ---=| If you're going to buy a pet - get a Shetland Giraffe |=---


Bookmarks

Posting Permissions

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