Manage iframe activity

2

Good evening everyone !!! I came to ask for a help from you. I'm building a .php page with html structure that contains an IFrame in your body. As soon as this .php page is opened, the iframe loads a web page that is not managed by me, but I can get the id's from its buttons, inputs, divs, etc. Well, there goes the question, is there any way to manage the activity on this webpage that is being loaded inside an iframe on my .php page? How can I capture the button clicks and input entries that are made on this web page? Please, if anyone knows, I am very grateful !!! I still do not understand much of javascript, but searching the sites of life I found this code below, I tried to implement the id's of elements of the web page, but it did not work. Note: id IFrame is IFrame of my page where the webpage is loading and ember516 is the id of an input of the web page.

<!DOCTYPE html>
<html>
<head>
    <title></title>
    <meta charset="utf-8">

<script type="text/javascript">
    function sendDataToIFrame(){
        var EUREKA = document.getElementById('IFrame').contentDocument.getElementById('ember516');
        EUREKA.innerHTML = "EUREKA!!!";
    }
</script>

</head>
<body>
<center><h3>VIDEOCENTER</h3></center>
<br>
<center><iframe id="IFrame" style="border:0; width:90%; height:900px; " src="linkdapáginaweb.html" frameborder="0" scrolling="no"></iframe></center>
</body>
</html>
    
asked by anonymous 25.07.2016 / 01:43

1 answer

1

Using jQuery , you can get through the following code.

$("#IFrame").contents()

So you can have access to the content. But this will only work if both the sites (yours and the iframe) have the same URL as the Source. If you try to do with a third-party site, you will receive a cross-origin error:

Uncaught DOMException: Failed to read the 'contentDocument' property from 'HTMLIFrameElement': Blocked a frame with origin "outro site" from accessing a cross-origin frame.

Browsers deprive this type of access for security reasons.

    
25.07.2016 / 22:18