开发者

Control styling of elements within iFrame

开发者 https://www.devze.com 2023-03-12 15:00 出处:网络
im not sure if this is possible or not, but im trying to alter the style of elements contained within an iFrame using javascript.

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

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号