Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 769765
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 14, 20262026-05-14T18:23:21+00:00 2026-05-14T18:23:21+00:00

i am beginner with chrome extension.There is simple problem. There is the code in

  • 0

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

    <!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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-14T18:23:22+00:00Added an answer on May 14, 2026 at 6:23 pm

    The return value of loadXmlFile is initialized to null and only set to something in the onreadystatechange callback, so at the time the function returns it is probably still null. Hence xmlDom is null on this line where you’re getting your error:

    var s = xmlDom.getElementsByTagName( "to" );
    

    That line and the alert should be within the innermost block of your onreadystatechange callback.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I'm trying to figure out how to write a simple Chrome extension which allows
I am a beginner with chrome extension. In my content_script.js, how can a get
Beginner in Android development. My code crashes. I have made a simple Java method
I am new and quite a beginner but i tried to write an extension
Something is wrong with my code. Chrome code spectrator say that there is probmel
Hi I am beginner in JS, Using linux ( Firefox, Chrome), Is there any
i'm a beginner at CSS and trying to do a NETTUTS , but there's
Beginner iOS dev here. I have a problem in my array. Im making an
Beginner level question Scenario: Have simple string cocantation tool, that I might expand later
Question : Beginner Level Code: Pure Javascript I had created a web page in

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.