Jquery gets the contents of the iframe

  • 2020-03-29 23:47:38
  • OfStack


     document.all('Iframe1').contentWindow.document.getElementById("deptName").width;

     $(window.parent.Iframe1.document.body).find('#deptName').width();

When calling an IFRAME across domains, access is denied. An untested solution was found on the web
      A review of the data shows that, by default, the browser prohibits scripts from accessing across domains, unless there is a necessary trust relationship between these domains.

      It is easy to find the problem, which can reduce the security level of the browser, but it is definitely bad for the user.

      So we need to add some js to the page
   
    try
    {
    document.domain = "xxx.net";
    }
    catch(e)
    {
    }
   
      Manually set the domain name of the child page and the parent page to the same, the problem can be solved.

Related articles: