错误,当我尝试使用JavaScript代码获取iframe的内容时,如图所示 [英] error when i try to obtain content of an iframe using javascript code as shown
本文介绍了错误,当我尝试使用JavaScript代码获取iframe的内容时,如图所示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在名为test_iframe的主窗口中有一个iframe。
I have an iframe within the main window named "test_iframe".
我想在google chrome扩展程序中访问test_iframe的内容。
I want to access the content of "test_iframe" within a google chrome extension.
访问这个iframe的内容,但我得到以下错误 - $ / b>
I am trying to access the content of this iframe, but I am getting the following error-
Uncaught TypeError: Cannot read property 'contentWindow' of null
我使用的javascript代码如下所示 -
The javascript code I have used is given below-
var htmlvar = document.getElementById('test_iframe').contentWindow.document.body.innerHTML;
代码有什么问题?如何使它工作?
What is wrong with the code? How can I make it work?
推荐答案
而不是编码中的test_iframe尝试folllwing
instead of test_iframe in coding try folllwing
<%=txtName.ClientID%>
i.e.
var htmlvar = document.getElementById('<%=txtName.ClientID%').contentWindow.document.body.innerHTML;
这篇关于错误,当我尝试使用JavaScript代码获取iframe的内容时,如图所示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文