Chrome extension:Cannot call method 'getElementsByTagName' of null
Posted
by T_t
on Stack Overflow
See other posts from Stack Overflow
or by T_t
Published on 2010-03-27T10:57:32Z
Indexed on
2010/03/27
11:03 UTC
Read the original article
Hit count: 267
Hi,i am beginner with chrome extension.There is simple problem. There is the code in my extension,but it do not work.I don't know how to figure it out. In my extension, i used a xml file to stroe some data.There is the code in my background.html,but it do not work,i don't know how to figure it out...
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<script>
function loadXmlFile(){
var xmlDom = null;
var xmlhttp = new XMLHttpRequest();
if( xmlhttp ){
xmlhttp.onreadystatechange = function(){
if( xmlhttp.readyState == 4 ){
if( xmlhttp.status == 200 ){
xmlDom = xmlhttp.responseXML;
}
}
}
xmlhttp.open( "GET",chrome.extension.getURL("/xml/123.xml"),true);
xmlhttp.send( null );
}
return xmlDom;
}
var xmlDom = loadXmlFile();
var s = xmlDom.getElementsByTagName( "to" );
alert( s[0].nodeType );
</script>
</body>
</html>
I used developer tools to debug,but it says " Cannot call method 'getElementsByTagName' of null"... who can help me?
© Stack Overflow or respective owner