Using iframe to introduce a page across domains on a local page, how can you manipulate the dom of the introduced page and bind events to dom?

<button id="btn"></button>
    <div id="iframeDecl">
      <iframe src="" name="iframeHtml" id="iframeHtml"></iframe> 
    </div>
js:
$(function(){
         $("-sharpbtn").click(function(){
           $("-sharpiframeHtml").attr("src","https://baidu.cn"); 
           $("-sharpiframeHtml").width($(window).width());
           $("-sharpiframeHtml").height($(window).height());

           var iframeDocument = $("-sharpiframeHtml")[0].contentDocument;
            $(iframeDocument ).ready(function(){
                alert("111");
                console.log($(this).find("-sharpbanner"))
                $(this).find("-sharpbanner").click(function(){
                    alert("....");
                });
            })
         })
       });

I want to implement a function, click the button on the local page, then introduce an external page through iframe, and then bind events to the dom elements in the external page.

Jul.19,2021

may be that iframe can only access pages under the same domain name and cannot cross domains;


binds you to heaven

Menu