How do you put only a certain section of a website into an iframe?

后端 未结 3 543
自闭症患者
自闭症患者 2021-01-31 22:18

I\'m looking to put only a small part of a website into an iframe. How would I do this? Usually when I set up a iframe for a website (lets say yahoo) it gets the whole website..

3条回答
  •  醉梦人生
    2021-01-31 22:56

    This can't be reliably done due to same origin policy and related iframe restrictions.

    .. the same origin policy is an important security concept for a number of browser-side programming languages, such as JavaScript. The policy .. prevents access to most methods and properties across pages on different sites.

    If it was your website in your website [or a proxy to the target site] then JavaScript in the parent could modify the DOM or CSS of the embedded iframe as desired ..

    If the target website is willing to communicate data through another means (including XDR/XHR+CORS), then those could potentially be used as hack-a-bouts as well. However, there is no general solution for this task.

    Even jQuery.load (which uses XHR) is limited by the same origin policy:

    Due to browser security restrictions, most "Ajax" requests are subject to the same origin policy; the request can not successfully retrieve data from a different domain, subdomain, or protocol.

提交回复
热议问题