html - Access iframe node given element node inside iframe using Javascript only -
say i'm given html element node, such
<div id = "content"></div>
and that's contained in iframe. it's passed in me node. want able iframe node element's in -- there's no specific id , want able access element node. i've tried
elnode.window
and
elnode.parent
but gives me undefined. i'm passed in current window, trying
curwindow.parent
just passes me in window, led no avail. want iframe element node. if has pointers, that's appreciated.
this issue due same-origin policy: browser won’t allow original script inspect contents of cross-origin document. more details sop https://en.wikipedia.org/wiki/same-origin_policy. generally, there following ways solves issue:
- using element has never been subject same-origin policy: download , execute script, regardless of origin.
- cross-document messaging,allows script 1 document pass textual messages script in document, regardless of script origins. calling postmessage() method on window object results in asynchronous delivery of message event (you can handle onmessage event handler function) document in window.
cross-origin resource sharing https://www.w3.org/tr/cors/ : draft standard extends http new origin: request header , new access-control- allow-origin response header. allows servers use header explicitly list origins may request file or use wildcard , allow file requested site.
- to support multi domain websites of sort, can use domain property of document object . but, domain value must have @ least 1 dot in it; cannot set “com” or other top-level domain. example ecar.car.com, pcar.car.com. can set domain car.com.
hope can give kind of help
Comments
Post a Comment