Issue
How to get iframe attributes inside iframe javascript code
<div>
<iframe src="http://192.168.0.108:8092/"
name="otherDomain"
width="100%"
height="600px"
style="border: 0;"
data-auth-token="xyz"
data-auth-key="abc"
>
</div>
I am trying with
console.log(window.frameElement.getAttribute('data-auth-token'))
If iframe url and browser user is same I am able to get iframe attributes. if the urls are different I am getting following error.
Uncaught SecurityError: Failed to read the 'frame' property from 'Window': Blocked a frame with origin "http://192.168.0.108:8092" from accessing a frame with origin "http://localhost:8092". Protocols, domains, and ports must match.
Is it possible to get cross domain iframe attributes inside JavaScript.
Solution
Unfortunately for you, it isn't possible to work with iframes that refer to another domain. The browser automatically blocks all the scripts that try to access the frame from another domain. If something like this was possible, then it would have been a huge security flaw.
In your case, you can set the iframe
attribute src
to localhost:8092
, so you'll have an iframe
with the same location (and the same domain name), and you'll be able to access its data.
Answered By - Marco Bonelli
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.