0

I am loading a domain into Iframe, there is a button "Delete". I want to click that button using Jquery or javascript. Chrome will not allow as SOP Policy.

<!DOCTYPE html>
<html>
<head>
    <title>Exploit me</title>
    <script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/1.12.4/jquery.min.js" integrity="sha256-ZosEbRLbNQzLpnKIkEdrPv7lOy9C27hHQ+Xp8a4MxAQ=" crossorigin="anonymous"></script>
</head>
<body>

<iframe id ="myframe" src="index.html"></iframe>


<button id = "click_me">click for color</button>




<script>
    $(document).ready(function() {
        $('#click_me').click(function() {
            // console.log("hu");
            // var x = document.getElementById("myframe");
   //       var y = x.contentDocument;

   //       y.getElementById("click").click();
   //       y.body.style.backgroundColor = "blue";

            document.getElementById("myframe").contentDocument.getElementById("click").click();

        });
     });
</script>


<!-- <script>
$(document).ready(function() {

    $( "#click" ).click();
});
</script>

<script>

$('#click').click(function() {
    alert("I am outer button");
});

</script> -->

</body>
</html>

My question here is, can I click into iframe loaded website through jquery and javascript which is added in my iframe.html

  • Possible duplicate of [jQuery/JavaScript: accessing contents of an iframe](https://stackoverflow.com/questions/364952/jquery-javascript-accessing-contents-of-an-iframe) – AP. May 26 '17 at 15:31
  • No, you said Same Origin Policy so you can't do it.... – epascarello May 26 '17 at 15:31
  • 2
    This question has been asked many times, if you want to access/interact with elements inside an iframe, you need to have the same domain on the host page, as the iframe. OR you need to enable CORS on the domain (of the iframe) – AP. May 26 '17 at 15:32

0 Answers0