How can I access the DOM elements within an iFrame

后端 未结 2 1731
星月不相逢
星月不相逢 2020-11-28 09:11

I am writing a jQuery Plugin that needs to be able to run against DOM elements within an iFrame. I\'m just testing this locally right now (ie url is file://.../example.html

2条回答
  •  刺人心
    刺人心 (楼主)
    2020-11-28 09:27

    Given that both the parent file and the iFrame's file are coming off my local disk (in development) and will be coming off the same server (in production) I'd have thought that I'd not be subject to the cross-origin issues.

    "Please open this perfectly harmless HTML document that I have attached to this email." There are good reasons for browsers to apply cross-domain security to local files.

    Is there a way I can convince the browser that my local files are actually of the same domain?

    Install a web server. Test through http://localhost. As a bonus, get all the other benefits of an HTTP server (such as being able to use relative URIs that start with a / and develop with server side code).

提交回复
热议问题