Get data from iframe

前端 未结 4 862
遇见更好的自我
遇见更好的自我 2020-12-20 13:05

I am doing this first time. I have created an iframe on my page and I want the text from the iframe through jquery. Here is my code :<

4条回答
  •  太阳男子
    2020-12-20 13:35

    Doing with jquery will be a little easier:

    $('Your Selector', frames['myIframe'].document)
    

    The above example will get anything from myIframe. But the iframe MUST be from the same domain as the parent document. If not from the same domain, a security violation occurs (You can't add content from foreign sites to your page and change that content.)

    If no security violation, you can do anything with the selection. For example you can use the jquery append() method to insert new html inside the iFrame, you can use the html() method to replace html or any other function that jquery/pure javascript allows.

提交回复
热议问题