suryaguruprakash suryaguruprakash - 4 months ago 13
Javascript Question

i want to get url from iframe

this is the code im using.............

i want to get current url(href) from below code ...............

<html>
<head>
<script type="text/javascript">
function load() {
var url = document.getElementById("iframeid");

//get the ifram onload url of href
//(i.e) http://www.image.com/home.html

}
</script>
</head>
<body>
<iframe onload="load()" name="Google" id="iframeid" scrolling="auto" style="width:95%;height:600px" src="http://www.image.com" >

</iframe>
</body>
</html>

Answer

This will work only if they are in the same domain,protocol and port:

document.getElementById("iframe_id").contentWindow.location.href

else use :

document.getElementById("iframe_id").src
Comments