// the iframe of the div I need to access
var iframe = document.getElementsByTagName("iframe")[2];
var innerDoc = iframe.contentDocument || iframe.contentWindow.document;
// resize 'player' in the iframe
innerDoc.getElementById('player').width = "1000px";
innerDoc.getElementById('player').height = "650px";
在userscript運行這個網址:http://www.free-tv-video-online.me/player/sockshare.php?id=24DA6EAA2561FD60鉻userscript錯誤:「不安全的JavaScript嘗試訪問框架」
爲什麼Chrome瀏覽器推出了這個錯誤和失敗的腳本?:
Unsafe JavaScript attempt to access frame with URL http://www.sockshare.com/embed/24DA6EAA2561FD60
from frame with URL http://www.free-tv-video-online.me/player/sockshare.php?id=24DA6EAA2561FD60.
Domains, protocols and ports must match.
(我只是一個基本的JavaScript用戶)
最終代碼,非常感謝回答者:
// ==UserScript==
// @name Resize
// @include http://www.free-tv-video-online.me/player/sockshare.php*
// @include http://www.sockshare.com/*
// ==/UserScript==
if (!(window.top === window.self)) {
var player = document.getElementById('player');
setSize(player);
}
function setSize(player) {
player.style.setProperty("width", "1000px");
player.style.setProperty("height", "650px");
}
哦,哇,完美的工作。把我的最終代碼放在OP中,謝謝你! –
不客氣,樂意效勞! –