55 users online (1 members and 54 guests)  


  Results 1 to 2 of 2

Related

  1. extract text between two strings    Forum: PHP Forum
    Replies: 2
  2. Help, generate all possible strings with Perl    Forum: CGI Perl Forum
    Replies: 1
  3. PHP Time Display    Forum: PHP Forum
    Replies: 2
  4. Replies: 5
  5. CSS Rollover display    Forum: CSS Forum
    Replies: 4
  1. #1
    choydogs's Avatar
    New User

    Status
    Offline
    Join Date
    May 2010
    Posts
    1

    Using Javascript, How do I display strings?

    Hi guys, I need help with javascript.

    Given that I have stored a variable in the parent window, how can i display it in an iframe? and I would like the displayed text in the iframe to update if i click on a button from the parent window. For example, a playlist like in mp3 player.

  2. #2
    coothead's Avatar
    bald headed old fart

    Status
    Offline
    Join Date
    Aug 2003
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    732

    Re: Using Javascript, How do I display strings?

    Hi there choydogs,

    and a warm welcome to these forums.

    Have a look at this example, you may be able to adapt it to your requirements...
    Code:
    
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html lang="en">
    <head>
    
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <meta name="language" content="english"> 
    <meta http-equiv="Content-Style-Type" content="text/css">
    <meta http-equiv="Content-Script-Type" content="text/javascript">
    
    <title>untitled document</title>
    
    
    <style type="text/css">
    #myiframe {
        display:block;
        width:600px;
        height:400px;
        border:3px double #fc9;
        margin:auto;
     }
    </style>
    
    <script type="text/javascript">
    
    function init(){
    
       c=0;
    
       text=['hello world from coothead','this is text two','this is text three','this is text four','goodbye world!!!'];
    
    
       d1='<div id="mydiv" style="width:296px;line-height:196px;border:2px solid #630;'+
          'text-align:center;background-color:#f93;color:#333;margin:100px 150px;">';
       d2='<\/div>';
    
       obj=document.getElementById('myiframe').contentWindow.document.body;
       obj.style.backgroundColor='#fc9';
       obj.style.margin=0;
       obj.innerHTML=d1+text[c++]+d2;
    
    document.getElementById('mybutton').onclick=function() {
    if(c==text.length) {
       c=0;
     }
       obj.innerHTML=d1+text[c++]+d2;
      }
     }
    
    if(window.addEventListener){
       window.addEventListener('load',init,false);
     }
    else { 
    if(window.attachEvent){
       window.attachEvent('onload',init);
      }
     }
    </script>
    
    </head>
    <body>
    
    <div>
     <iframe id="myiframe" ></iframe>
    </div>
    
    <div>
    <input id="mybutton" type="button" value="click me">
    </div>
    
    </body>
    </html>