简体   繁体   中英

Copying contents from iframe into input

Hi new to coding and scripting, here is what I have:

<html>
<body>

<p align="left"><iframe id="aa" style="HEIGHT: 25px; WIDTH: 227px"src="http://www.html-assets.com/assets/html-building-blocks/php-display-user-ip-address.php" frameborder="0" width="600" name="aa" scrolling="no"></iframe></p>



</br><input type="text" id="ee">

<input type="checkbox" name="dd" value=" onclick="myFunction()"><em>Check the box to     copy the IP Address above</em>

<script>
myFunction() {


var x = document.getElementById("aa");
var y =(x.contentWindow || x.contentDocument);

if(dd.oncheck==true){
f.ee.value = y;
}
}
</script>

</body>
</html>

What I am trying to do is have something where the page lists out the IP Address of an end-user. I want the user to have the ability to copy this address into an input field that can be added to a form that can be submitted.

How would I script this? At this point, the object in my iframe is outside my domain; is this impossible to call because of the same origin policy? I am planning on creating this using a .php within our own domain; I will adjust the code accordingly.

Yes, you will have to use a .php file for this.

Once you have created your php file, then insert this code:

<?php
$userip = $_SERVER['REMOTE_ADDR'];
?>
<input type="text" value="" id="textbox1"/>
<input type="button" value="Click me" onClick="document.getElementById('textbox1').value = '<?php echo $userip;?>' "/> 

The user's ip will be saved in the variable $userip . Then, when the button is pressed, the textbox textbox1 will be filled with the user's ip address.

I hope this helps!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM