location.href of iframe contents
A Flash Developer Resource Site

Results 1 to 3 of 3

Thread: location.href of iframe contents

  1. #1
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,046

    location.href of iframe contents

    now this is really weird:
    Code:
    <html>
    <head>
    <title>test</title>
    </head>
    
    <body>
    <iframe name="test_frame" width="600" height="300"></iframe><br />
    <input type="button" value="change iframe" onclick="test_frame.location.href='http://google.com';" />
    <input type="button" value="check href" onclick="alert(test_frame.location.href);" />
    </body>
    </html>
    using that code, if you click the "check href" button first, you get an alert that says "about:blank" like it should, but if you click "change iframe" and allow google to load into the iframe, then click "check href", NOTHING. no alert, no nothing. How can i retrieve the location from the iframe after a page has been loaded into it?

    This is confusing me because I've never really taken the time to learn javascript, and i guess this is why!

  2. #2
    Senior Member catbert303's Avatar
    Join Date
    Aug 2001
    Location
    uk
    Posts
    11,222
    I think it's possible location.href is not allowed to be read for security reasons. Although it seems that if you work with the iframe using it's src attribute things will work. Here's a quick example,

    Code:
    <html>
    <head>
    <script type="text/javascript">
    
    function getSrc() {
        return document.getElementById('test-frame').src;
    }
    
    function setSrc(value) {
        document.getElementById('test-frame').src = value;
    }
    
    </script>
    
    </head>
    <body>
    
    <iframe id="test-frame" src="about:blank" width="500" height="400"> </iframe>
    
    <a href="javascript:alert(getSrc());">getSrc</a> 
    <a href="javascript:setSrc('http://www.google.com');">setSrc('http://www.google.com')</a> 
    
    </body>
    </html>

  3. #3
    Bearded (M|G)od MyFriendIsATaco's Avatar
    Join Date
    Dec 2002
    Location
    Awesomeville.
    Posts
    3,046
    yeah, i actually stumbled upon reading the src attribute. but then, my ultimate goal is to have a form post variables into a page which is loaded in the iframe. the page inside the frame evaluates the vars that were posted, then it kicks to a different page depending on what the variables were. then i wanted to grab the new href of the page, and do something based on what it was. but, im thinking its not going to happen. oh well, thanks anyways!

Posting Permissions

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




Click Here to Expand Forum to Full Width


HTML5 Development Center

Poll by Flashkit.com