[英]jQuery: How to manipulate the contents of an iframe when the src is a different domain?
我有一個加載頁面的iframe,並且我想操縱其中的內容。
例如:
<iframe id="myIframe" src="http://www.google.com"></iframe>
<script>
$(document).ready(function(){
$(iframeContents).css('background-color', '#000');
});
</script>
我怎樣才能做到這一點?
你不能。 同源起源策略禁止這樣做。
正如Pekka所說,不能,不能直接。 JavaScript安全模型禁止這樣做。 但是,如果iFrame中的域與腳本運行所在的域相同,則可以執行此操作。 因此,可以做的是在自己的域上設置代理,並通過代理在iFrame中顯示內容,然后使用JS與之交互。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.