开发者

error when i try to obtain content of an iframe using javascript code as shown

开发者 https://www.devze.com 2023-04-03 18:32 出处:网络
I have an iframe within the main window named \"test_iframe\". I want to access the content of \"test_iframe\" within a google chrome extension.

I have an iframe within the main window named "test_iframe".

I want to access the content of "test_iframe" within a google chrome extension.

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

The javascript code I have used is given below-

var htmlvar = document.getElementById('te开发者_JAVA百科st_iframe').contentWindow.document.body.innerHTML; 

What is wrong with the code? How can I make it work?


instead of test_iframe in coding try folllwing

    <%=txtName.ClientID%>

i.e.

    var htmlvar = document.getElementById('<%=txtName.ClientID%').contentWindow.document.body.innerHTML; 
0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号