简体   繁体   中英

Setting iframe src from JS / jQuery gives DOMException:cross-origin

I'm trying to set a iframe src (with a relative path) attribute with JS / jQuery and it throws DOMException. If I set the src attribute directly in the HTML this error isn't thrown, just when I set it by JS or jQuery. It's the same application so it doesn't have any sense for me, any suggestion?

Although an exception is thrown it works, but don't know why it gives the exception.

VM45:21 Uncaught DOMException: Blocked a frame with origin "https://localhost:8123" from accessing a cross-origin frame. at fix (eval at dj_eval (https://localhost:8123/sisvel/lib/dojo/dojo.js:108:33), <anonymous>:21:8) at fix (eval at dj_eval (https://localhost:8123/sisvel/lib/dojo/dojo.js:108:33), <anonymous>:23:5) at Object.dojo.html.getDocumentWindow (eval at dj_eval (https://localhost:8123/sisvel/lib/dojo/dojo.js:108:33), <anonymous>:26:3) at Object.registerAllWindows (eval at dj_eval (https://localhost:8123/sisvel/lib/dojo/dojo.js:108:33), <anonymous>:212:29) at Array.<anonymous> (https://localhost:8123/sisvel/lib/dojo/dojo.js:259:9) at Object.dojo.hostenv.loaded (https://localhost:8123/sisvel/lib/dojo/dojo.js:239:7) at Object.dojo.hostenv.callLoaded (https://localhost:8123/sisvel/lib/dojo/dojo.js:295:14) at Object.dojo.hostenv.modulesLoaded (https://localhost:8123/sisvel/lib/dojo/dojo.js:288:14) at dj_load_init (https://localhost:8123/sisvel/lib/dojo/dojo.js:851:14)

Its a security feature built into your browser to stop the user from falling for scams where genuine pages are encapsulated within fake frames and then interrogated.

No way around it with iframes I'm afraid.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM