SitePoint Sponsor

User Tag List

Results 1 to 3 of 3
  1. #1
    SitePoint Addict
    Join Date
    Jul 2004
    Location
    Brooklyn, NY
    Posts
    316
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Getting iFrame's URL through Javascript

    here's the thing, I'm using the iframe as a "browser" within the page
    on top of the iFrame I've got an input box that I want to use as the address bar

    so I did some reading and I can see it's not possible due to security issues, because they're different domains

    but maybe there's a way to get the URL through server side, an xmlhttprequest perhaps?


    the only person that's ever going to use this is me, and only on my home PC
    maybe there's a way to change the browser security settings to make this work? (running Firefox 1.5)

    here's the code I'm using that's obviously not working
    Code:
    var url=document.getElementById('preview').src;
    document.getElementById('addressBar').value=url;
    any suggestions are welcome

  2. #2
    SitePoint Addict Mirek Komárek's Avatar
    Join Date
    Dec 2006
    Location
    Prague
    Posts
    210
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Try online!, because offline it will not works (browser has prevention of cross site scripting).
    Code:
    <input type="text" id="addressBar" value="http://www.google.com">
    <input type="button" onclick="document.getElementById('addressBar').value=parent.frames['preview'].location.href">
    <iframe src="http://www.google.com" id="preview" name="preview">

  3. #3
    SitePoint Wizard
    Join Date
    Mar 2001
    Posts
    3,537
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    the only person that's ever going to use this is me, and only on my home PC
    Unfortunately, your browser doesn't care. It's js has to conform to security restrictions.

    but maybe there's a way to get the URL through server side, an xmlhttprequest perhaps?
    I don't see how. Essentially, the server would receive a request from a client side page asking a server side program to find out the url of a some other page on the client side. Wouldn't the server side page respond to the page request like so: "I'm all the way over here on the other side of the internet, why don't you get it?"
    Last edited by 7stud; Jan 13, 2007 at 04:05.


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
  •