Control styling of elements within iFrame
im not sure if this is possible or not, but im trying to alter the style of elements contained within an iFrame using javascript.
I have tried the following which I believed in theory should work with no luck..开发者_高级运维.
<script>
function click() {
window.frames[0].document.getElementById('daLink').style.backgroundColor="#000";
}
</script>
<a href="#" onclick="click()" >Test</a>
<iframe src="http://www.google.co.uk" width="600" height="400" id="daLink"></iframe>
That will only work if the iFrame Source is on the same domain. Your code is not working due to the same-origin-policy!
Read more here: Javascript Security
精彩评论