Manage iframe activity

Asked

Viewed 70 times

2

Good evening guys!!! I came to ask you for a help. I am building a page. php with html structure that contains an Iframe in your body. Just when this page . php is opened iframe loads within itself a web page that is not managed by me, but I have how to get the id s of your buttons, inputs, div s etc. Good, There goes the question, there is how to manage the activity on this web page being loaded inside an iframe on my page . php? Is there a way to capture the clicks of buttons and input that are performed on this web page? Please if anyone knows I am very grateful!!! I still don’t know much about 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 didn’t work. Obs.: the id IFrame is from IFrame of my page where the web page is being loaded and the ember516 is the id of a web page input.

<!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>

1 answer

1


Using jQuery, you can catch through the following code.

$("#IFrame").contents()

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

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.

  • vlw @Douglasfernandes I’m sorry it doesn’t give :(

Browser other questions tagged

You are not signed in. Login or sign up in order to post.