is it possible to create page with button and iframe window, that when the user click on the button it take him to the current url of the iframe window?
Asked
Active
Viewed 1,664 times
2
-
`top.location.href = window.location.href;` – DaveRandom Dec 20 '12 at 12:46
-
daverandom, but if the iframe it's google.com and the user enter to other site in the user? – Idan Neeman Dec 20 '12 at 12:47
-
Clear your question. Some code example... and what's the relation between your question and PHP? – SaidbakR Dec 20 '12 at 12:50
3 Answers
2
document.location = document.getElementById("iframe_id").contentWindow.location
assuming your serving the Javascript from the same domain, else you'll run into XSS vulnerabilities.
-
-
@hd1's point is very salient - you won't be able to get the URL of the iframe when it is focussed on Google due to cross-domain scripting vulnerabilities. The browser simply won't let you get it. – n00dle Dec 20 '12 at 13:36
-
0
<html>
<head>
<script type="text/javascript">
function FrameUrl()
{
alert('url = ' + document.frames['frame1'].location.href);
}
</script>
</head>
<body>
<a href="#" onclick="FrameUrl();">Find the iFrame URL</a>
<iframe name="frame1" src="http://www.facebook.com" width="100%" height="400"></iframe>
</body>
</html>

Nirav Ranpara
- 13,753
- 3
- 39
- 54
0
This correct as mention by "DaveRandom"
top.location.href = window.location.href

Suresh Kamrushi
- 15,627
- 13
- 75
- 90