Access jQuery data from iframe element

前端 未结 2 1505
时光说笑
时光说笑 2020-12-13 16:25

Lets say I have a page on the same domain that I put inside an iframe. In the iframe, I have added data to an element, something like this:

HTML

2条回答
  •  春和景丽
    2020-12-13 17:15

    I have never tried this, but I'm pretty certain you need to talk to the iframe's $ object instead of your document's one to access that object's internal data storage. Not 100% sure how to do that - maybe something like

    $('#frame').contents().jQuery.find("#data").data("test")
    

    (wild guess)

    What would work for sure is a function inside the iframe document that fetches the data, and returns it to you. But that's much less elegant than fetching it directly, of course.

提交回复
热议问题