SE_Danny Posted December 3, 2010 Share Posted December 3, 2010 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. Link to comment Share on other sites More sharing options...
jeffman Posted December 3, 2010 Share Posted December 3, 2010 Not difficult. In JavaScript, you can GET the URL with the following (assume your iframe has an id="myframe"):document.getElementById("myframe").srcYou can CHANGE the URL like this:document.getElementById("myframe").src="http://www.somewhere.com" Link to comment Share on other sites More sharing options...
SE_Danny Posted December 3, 2010 Author Share Posted December 3, 2010 Yes i did know that, but here's the problem : the iframe loads extrernal domains Link to comment Share on other sites More sharing options...
10 weber Posted December 3, 2010 Share Posted December 3, 2010 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 Link to comment Share on other sites More sharing options...
SE_Danny Posted December 3, 2010 Author Share Posted December 3, 2010 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 comment Share on other sites More sharing options...
10 weber Posted December 3, 2010 Share Posted December 3, 2010 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> Link to comment Share on other sites More sharing options...
SE_Danny Posted December 6, 2010 Author Share Posted December 6, 2010 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 comment Share on other sites More sharing options...
SE_Danny Posted December 6, 2010 Author Share Posted December 6, 2010 please guys !this is really important to me. 10weber already found an interesting script. Maybe a more advanced user can just help me out here ?? Link to comment Share on other sites More sharing options...
SE_Danny Posted December 10, 2010 Author Share Posted December 10, 2010 so nobody on the forum knows how to solve that ?? I really just need to get the url of an iframe loading external domains. Link to comment Share on other sites More sharing options...
dsonesuk Posted December 10, 2010 Share Posted December 10, 2010 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. Link to comment Share on other sites More sharing options...
SE_Danny Posted December 11, 2010 Author Share Posted December 11, 2010 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 comment Share on other sites More sharing options...
retro-starr Posted December 21, 2010 Share Posted December 21, 2010 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 comment Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.