Gmail getElementById('canvas_frame')保持返回null在谷歌Chrom
Gmail getElementById('canvas_frame') keeps returning null in Google Chrome
我正在尝试为Gmail扩展编写JavaScript代码,当我试图获得画布框架i时,"getElementById"一直返回null
值。
var doc2 = document.getElementById('canvas_frame').contentDocument;
我得到以下错误:
"Uncaught TypeError: Cannot read property 'contentDocument' of null"
我该如何解决这个问题?
因为ID为canvas_frame
的iframe不需要在Gmail中存在
要获得对相关文档的引用,您可以首先尝试获取对iframe#canvas_frame
的引用,如果失败,请检查当前上下文是否正确:
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
相关文章:
- Meteor方法在客户端返回null,在客户端运行的相同方法返回正确的值
- php函数的ajax html$_POST值返回null
- 是否可以 document.getElementsByTagName('head')[0] ever 返回 null
- Firebase:查询返回null
- 在浅层渲染的反应组件上,Enzyme为道具返回null
- jQuery Multiselect插件返回null长度(应为0?)
- 如何处理getElementById返回Null
- JavaScript中的RegExp返回null
- Javascript 中的 RegEx 返回 Null
- 加载时的getelementbyID返回null
- 谷歌脚本在第二次调用Gmail后返回null
- Indexeddb OpenCursor在特定键值上返回null
- Ajax响应返回null
- 有没有一种方法可以判断图像src是否在javascript内部返回null
- 当JS在Chrome控制台上正常工作时,Selenium JavaScript执行器返回null
- Auth$getUser返回null,即使用户已登录(AngularFire,Firebase)
- Mongoose JS findOne总是返回null
- 为什么我的ajax调用返回null
- 当与全局标志一起使用时,Javascript Regex在后续调用中返回null
- Regex以确定该值在JS中是否有效,返回null