Gmail getElementById('canvas_frame')在Google Chrome中始终返回null [英] Gmail getElementById('canvas_frame') keeps returning null in Google Chrome
问题描述
我试图为Gmail扩展程序编写JavaScript代码,并且当我试图获取画布框架时,getElementById会一直返回 null
值。
以下是我使用的代码:
var doc2 = document.getElementById('canvas_frame')。contentDocument;
我收到以下错误:
< pre $ Uncaught TypeError:无法读取属性'contentDocument'为null
如何解决这个问题?
因为iframe的ID 要获得对相关文档的引用,您可以先尝试获取对 i'm trying to write JavaScript code for a Gmail extension, and when I'm trying to get the canvas frame I, "getElementById" keeps returning the Here is the code I'm using: I'm getting the following error: How can I solve this? Because the iframe with ID To get a reference to the relevant document, you can first try to get a reference to
这篇关于Gmail getElementById('canvas_frame')在Google Chrome中始终返回null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋! canvas_frame $ c
的引用, iframe#canvas_frame
,如果失败,检查当前上下文是否正确:
var doc2 = document.getElementById('canvas_frame');
if(doc2){
doc2 = doc2.contentDocument;
} else if(document.getElementById('js_frame')){
//如果#canvas_frame不存在,但是#js_frame确实存在,那么Gmail会呈现
// main = top)frame
doc2 = document;
} // else not Gmail's document and doc2 === null
null
value.var doc2 = document.getElementById('canvas_frame').contentDocument;
"Uncaught TypeError: Cannot read property 'contentDocument' of null"
canvas_frame
does not need to exist in Gmail.iframe#canvas_frame
, and if that fails, check if the current context is correct:var doc2 = document.getElementById('canvas_frame');
if (doc2) {
doc2 = doc2.contentDocument;
} else if (document.getElementById('js_frame')) {
// If #canvas_frame does not exist, but #js_frame does, then Gmail renders
// everything in the main (=top) frame
doc2 = document;
} // else not Gmail's document, and doc2 === null