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 3 of 3
  1. #1
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Question [ASK]Accessing outside elements from an iframe

    I have a page:
    Code:
    <html>
    <body>
      <b id="btext">Hi! I am a bold text</b><br>
      <i id="itext">And I am a italic text</i>
      <iframe name="myiframe" width="200px" height="100px" src="myframe.html"></iframe>
    </body>
    </html>
    And wat i wanna do is like changing the font color of that <b id="btext"> element from myframe.html.
    In other words, [B]styling[

    Can that kind of things will happen?
    How to do this?
    Please help me guys!...

  • #2
    Senior Coder coothead's Avatar
    Join Date
    Jan 2004
    Location
    chertsey, a small town 25 miles south west of london, england.
    Posts
    1,736
    Thanks
    0
    Thanked 241 Times in 236 Posts
    Hi there alvin_bilian,

    try it like this...

    mypage.html
    Code:
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <style type="text/css">
    div {
        margin:5px 0;
     }
    #btext {
        font-weight:bold;
     }
    #itext {
        font-style:oblique;
     }
    #myiframe {
        width:200px;
        height:100px;
     }
    .red {
        color:#f00;
     }
    </style>
    
    </head>
    <body>
    
    <div id="btext">Hi! I am a bold text</div>
    <div id="itext">And I am a italic text</div>
    
    <div><iframe id="myiframe" src="myframe.html" scrolling="0"></iframe></div>
    
    </body>
    </html>
    
    myiframe.html
    Code:
    
    <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
       "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <title></title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    
    <style type="text/css">
    body {
        margin:0;
        padding:0;
     }
    #changer {
        line-height:30px;
        text-align:center;
        margin:35px 0;
        cursor:pointer;
     }
    </style>
    
    <script type="text/javascript">
    window.onload=function() {
       document.getElementById('changer').onclick=function() {
       parent.document.getElementById('btext').className='red';
      }
     }
    </script>
    
    </head>
    <body>
    
    <div id="changer">change btext color</div>
    
    </body>
    </html>
    
    coothead

  • #3
    New to the CF scene
    Join Date
    Dec 2006
    Posts
    8
    Thanks
    0
    Thanked 0 Times in 0 Posts
    Nice Dude!! Its working!!
    Thanks!!
    Last edited by alvin_bilian; 12-22-2006 at 05:09 AM.


  •  

    Posting Permissions

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