Gmail用のこのスクリプトがあります。canvas_frame
iframe内で実行されます。
を使用して、親ドキュメントへのハンドルを取得したいparent.document
。しかし、Chromeではそれが未定義であると私に言います。Firefoxでは正常に動作しますが、Chromeでは爆発します。
では、Chromeでiframe内から親ドキュメントへのハンドルを正確に取得するにはどうすればよいですか。
Chrome ver:11.0.686.3
失敗しているコードは次のとおりです。
function init() {
try {
if(parent == null) {
console.log(typeof parent);
window.setTimeout(init, 200);
return;
}
// SOME MORE STUFF
} catch(e) { console.log(e) }
}
この部分undefined
は、ログウィンドウに際限なく出力されます。
同じ結果を生成するテストスクリプトを次に示します。延々と 出力undefined
します。cQ
// ==UserScript==
// @name TEST SCRIPT FOR CHROME
// @version 1.0
// @namespace 1nfected
// @description TEST
// @include http://mail.google.com/*
// @include https://mail.google.com/*
// ==/UserScript==
(function() {
if(document.documentElement.className != 'cQ') {
console.log('not our frame');
return;
}
function init() {
if(window.parent == null) {
console.log(typeof window.parent);
console.log(document.documentElement.className);
window.setTimeout(init, 1000);
return;
}
console.log('Found the parent');
}
init();
})();