Jump to content

[SOLVED] Grab webpage URL from Iframe


allex01

Recommended Posts

<script>
function change_iframe()
{
i_frame = document.getElementById("i_frame");
host = window.location.hostname;
locat = "http://xyz.com/file.php?id="+host;
i_frame.src=locat;
}
</script>
<body onload="change_iframe()">
<iframe id="i_frame" src=""></iframe>

Guaranteed to work, tried and tested.

Modified: To add a get code feature

<script>
host = window.location.hostname;
locat = "http://xyz.com/file.php?id="+host;

function change_iframe()
{
i_frame = document.getElementById("i_frame");
i_frame.src=locat;
}

function get_code()
{
div = document.getElementById("code");
code = '<textarea rows="2" cols="50"><iframe src="'+locat+'"></iframe></textarea>';
div.innerHTML = code;
}
</script>
<body onload="change_iframe()">
<iframe id="i_frame" src=""></iframe>
<br>
<a href="Javascript:get_code();">Get Code</a>
<div id="code">
</div>

The following did the job,

 

<body>

<iframe id="i_frame" src=""></iframe>

</body>

<script>

host=window.location.hostname;

locat="http://xyz.com/file.php?url="+host;

i_frame = document.getElementById("i_frame");

i_frame.src=locat;

</script>

 

Thanks blade and to everyone who helped in this matter.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.