iFrame and PHP or javascript

I am posting this in the PHP forum but this maybe something done with javascript. If someone can point me in the right direction, I would appreciate it. I have an iframe. The iframe is an amazon store. I need to take the current url from the iframe and insert the link in a textfield. I do this with javascript but it doesn’t work as expected. Also after a certain text string (says buy now) I need to put the dollar amount in another textfield. Is this better to do with php or javascript? I would prefer PHP since the system is PHP. Again any help would be appreciated

There is no need for PHP here. You only need javascript.

var frameSRC = document.getElementById("my_iFrame").src; 

Also after a certain text string (says buy now) I need to put the dollar amount in another textfield

Where is the textfield? Is it into your iframe?
Can you control it with javascript (is it on your server)?

Thanks and Yes, I used the document.getElementById(“my_iFrame”).src; and it works but if someone goes to a new page in the iframe it does ny get the new page. It just gets the original page.

I can control the page with the text in the iframe.

It will only work on the same server (same domain).
However, you can set the value of that field after the button click, without checking the iframe.


<a href="http://localhost/__tests/json.php" target="go">page json</a>
<a href="http://localhost/__tests/image1.php" target="go">page image1</a><br />
<input type="text" id="checkURL" style="width:300px" />
<iframe name="go" id="go" style="width:300px;height:100px" src="http://localhost/__tests/json.php"></iframe>

<script>
function getIframeSrc() {
	return document.getElementById('go').contentWindow.location.href;
}
function setTextfield() {
	document.getElementById('checkURL').value = getIframeSrc();
}
setTextfield();
setInterval(function(){
	getIframeSrc();
	setTextfield();
}, 200);
</script>