Iframe cross-domain access with JavaScript


Joined
Oct 14, 2022
Messages
1
Reaction score
0
Hello
I have a simple HTML page with an iframe. I set the src to another HTML file and I can change the style of any chosen element at will using code like this (a very basic example):
function elementStyle() { var iFrame = document.getElementById( "iFrame" ); var element = iFrame.contentWindow.document.getElementsByTagName( "table" )[0]; element.style.color = "#ff0000"; }

However the src of the iframe must be an external URL and cross-domain restriction prevents me from accessing its elements. I have no control over its content so I can't use postMessage() because I can't receive the message posted.
Any ideas of a way to get round this?

Note: it must work for anyone with any browser so musn't use any special methods (jQuery, CORS etc).
Thanks
 
Ad

Advertisements

Joined
Mar 11, 2022
Messages
225
Reaction score
29
That's why cross policy came up. There is no hack for that (fortunately). If you don't have any access to the src domains FTP or server stuff, there is nothing you can do. Otherwise everybody could include Facebook in his or her own domain and do some crap arround it.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top