Jump to content

Recommended Posts

Hi guys !I looked all over the internet to find out how to get the url of an iframe that loads an extrenal domain. I found something interesting that's called 'proxy'. Proxies like these (http://proxy.org/) show a dynamic url on the top. And that's exactly what I want to do with the url of an iframe.I suppose this very difficult. Can someone please help me ??Thanks !Daniel.

Edited by SE_Danny
Link to post
Share on other sites
Yes i did know that, but here's the problem : the iframe loads extrernal domains :)
You can open the iframe with the JS window.open function and get it's url by using location.href:
//define:var iframe = open([i]url[/i], [i]iframe's_name[/i]);//getURL:iframe.location.href

Edited by 10 weber
Link to post
Share on other sites
You can open the iframe with the JS window.open function and get it's url by using location.href:
//define:var iframe = open([i]url[/i], [i]iframe's_name[/i]);//getURL:iframe.location.href

I tested that but it didn't work. Because I don't know the url to put into 'open(url, iframename);'I try to get it through the script. And once the iframe was opened I can't get the location.herf because this part of the script is still in the first window, and the script redirected me to the iframe window. Or did I do anything wrong ?
Link to post
Share on other sites
I tested that but it didn't work. Because I don't know the url to put into 'open(url, iframename);'I try to get it through the script. And once the iframe was opened I can't get the location.herf because this part of the script is still in the first window, and the script redirected me to the iframe window. Or did I do anything wrong ?
I'm not sure I understand, but you can copy the next code to the Tryit Editor:
<html><head><script type="text/javascript">var iframe;window.onload = function(){iframe = open("", "iframe");};</script></head><body><iframe name="iframe" style="width:100%;"></iframe><br/><input type="text" id="url" style="width:100%;" /><br/><button onclick="document.getElementById('url').value = iframe.location.href;">getURL</button><button onclick="iframe.location.href = document.getElementById('url').value;">setURL</button></body></html>

Edited by 10 weber
Link to post
Share on other sites
I'm not sure I understand, but you can copy the next code to the Tryit Editor:
<html><head><script type="text/javascript">var iframe;window.onload = function(){iframe = open("", "iframe");};</script></head><body><iframe name="iframe" style="width:100%;"></iframe><br/><input type="text" id="url" style="width:100%;" /><br/><button onclick="document.getElementById('url').value = iframe.location.href;">getURL</button><button onclick="iframe.location.href = document.getElementById('url').value;">setURL</button></body></html>

That's an awesome idea ! But it it isn't working either. Because the page has to be on the same domain. Try it with the ifame src "http://google.com" and it will not get the url.But thanks a lot for you help :) Maybe someone can develop and add a few things to this script ?
Link to post
Share on other sites

I'm not clear what the problemn is? DD gave a perfectly sound way of retrieving the the src/url of an iframe it does not matter if it is external domain or not, you control the src not the external domain, i could understand if you wanted to retrieve specific information from what is actually within the external webpage, but its source is controlled by you.example below, they are all external domains, but i can retrieve the src with no problem, either on local server, or web server.

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>Untitled Document</title>  <script type="text/javascript"> /*<![CDATA[*//*---->*/   window.onload=function() { for(i=0;i<3;i++) { alert(document.getElementById("myframe"+i).src) } } /*--*//*]]>*/ </script>     <style type="text/css"> </style> </head> <body>  <iframe id="myframe0" src="http://google.co.uk"></iframe> <iframe id="myframe1" src="http://bing.co.uk"></iframe> <iframe id="myframe2" src="http://uk.yahoo.co.uk"></iframe>   </body> </html>

If you mean the CURRENT url, from when the user moves away from the initial src address, then you are not going to get that with an external domain.If you should try, all you will get is "Permission denied" error.

Edited by dsonesuk
Link to post
Share on other sites
If you mean the CURRENT url, from when the user moves away from the initial src address, then you are not going to get that with an external domain.If you should try, all you will get is "Permission denied" error.
This is what I'm trying to do. Get the current url.Ok Thanks anyway.
Link to post
Share on other sites
  • 2 weeks later...

I wanted to do the same thing as you and here's what I got! There is also a project on Mozilla Labs called Chromeless, you should go take a look. It's what we want to do, but extremely well done. My script below is not 100% as I'm still dissecting (address_bar2() is my attempt at understanding what's happening in #1) and need to put in the proper formatting to make it look pretty. SE_Danny was right, it looks though as if he needed the window object.

<html><head><title>Webby Fox</title><script type="text/javascript" src="jquery-1.4.4.js"></script><script type="text/javascript">// back + forward + reload buttons// mod code from: [url="http://www.javascriptfreecode.com/25.htm"]http://www.javascriptfreecode.com/25.htm[/url]function goHist(a) { history.go(a);}// address bar + go button// mod code from: [url="http://www.javascriptfreecode.com/83.htm"]http://www.javascriptfreecode.com/83.htm[/url]function address_bar(variable){ var site = variable.address.value; // variable; input name; "value" if (site != "") {  var site = "http://" + site; } window.open(site, 'url_content').location.href;}// address bar + go button// self-made codefunction address_bar2(){ var site = document.getElementsById("go_button").childNodes[0].nodeValue; if (site != "") {  var site = "http://" + site; } window.location.assign(site); //document.write(document.URL); // returns current address}</script><style type="text/css">// make an entry for iframe</style></head><body><div id="navigation_area"> <div id="history_buttons">  <button type="button" onClick="goHist(-1)"><img src="" alt="<" /></button>  <button type="button" onClick="goHist(1)"><img src="" alt=">" /></button>  <button type="button" onClick="goHist(0)"><img src="" alt="R" /></button> </div> <div id="address_bar">   <form method="post">    <input type="text" name="address" value="" />    <div id="go_button">     <button type="button" onclick="address_bar(form)"><img src="" alt="GO" /></button>    </div>   </form> </div></div><div id="url_content"> <iframe name="url_content" height="80%" width="100%" frameborder="0" src=""></iframe></div></body></html>

Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
×
×
  • Create New...