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 6092635
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T12:27:55+00:00 2026-05-23T12:27:55+00:00

I have this code: <script type=text/javascript> var url = http://www.xxxxx.xxx/xxxxxxxxx; var txt; var id1;

  • 0

I have this code:

<script type="text/javascript">
var url = "http://www.xxxxx.xxx/xxxxxxxxx";

var txt;
var id1;
var id2;
var imgarres = [];
var imgarr = [];
var imgels = [];

function getdata() {
    if (id1){clearTimeout(id1);}
    if (id2){clearTimeout(id2);}

    var xhr = new XMLHttpRequest();
    xhr.open('GET',url, true);
    xhr.setRequestHeader('Cache-Control', 'no-cache');
    xhr.setRequestHeader('Pragma', 'no-cache');

    xhr.onreadystatechange = function() {
        if (xhr.readyState == 4)  {
            txt = xhr.responseText;

            var r = txt.indexOf('<b class="fl_r">Online</b>');
            var el = document.createElement("div");

            el.innerHTML = txt;

            var n = imgprocess(el);     
            var nam = el.getElementsByTagName("title")[0].innerHTML;

            if (r != -1) {
                var notification = webkitNotifications.createNotification('plus.gif',  nam, 'online!!' );
                notification.show();
                var id1 = setTimeout(getdata, 60000);
            } else {
                var notification = webkitNotifications.createNotification(n,  nam, 'offline!!' );
                notification.show();
                var id2 = setTimeout(getdata, 600000);
            }
        }
    }

    xhr.send();    
}

function imgprocess(text) {
    imgels = text.getElementsByTagName("IMG");
    for (var i=0;i< imgels.length;i++) {
        if (imgels[i].src.indexOf(parse(url)) != -1) {
            imgarr = imgels[i];
        }
    }

    for (var p=0; p< imgarr.length; p++) {
        if (imgarr[p].parentNode.nodeName=="A") {
            imgarres = imgarr[p];
        }
    }

    var z = imgarres[0].src;
    return z; 
}

function init() {
    getdata();
}
</script>
</head>
<body onload="init();">

When I execute this code, error says “src cannot be read of undefined” about var z = imgarres[0].src; When I remove src from that line, extension works without errors, but
imgprocess routine doesn’t return expected value! The expected value is imgurl, which is in src that I removed. It seems that the second for loop (for (var p=0; p< imgarr.length; p++){) doesn’t run at all, but the first one is OK. How do I fix this?

P.S.: I tried passing callback like this: xhr.onreadystatechange = function(imgprocess) {
but it doesnt work. It says “uncaught typeerror” object is not a function.

  • 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-23T12:27:56+00:00Added an answer on May 23, 2026 at 12:27 pm
     if (imgels[i].src.indexOf(parse(url)) != -1){
        imgarr = imgels[i];
     }
    

    it looks like you’re overwriting an array with a single element in the above code.

    Added edit:

    If the if condition is true, imgels[i] is an element (with an src) but instead of adding imgels[i] to the imgarr array, you are changing imgarr to point to a single element.

    Then in the second for loop, you are treating it as an array.

    In fact, this is also a mistake in the second loop. Is imgarres supposed to be an array or not? If it is then imgarres = imgarr[p]; is wrong (it points to an element after you do that). If it isn’t then var z = imgarres[0].src; is wrong (if it is an element you don’t need the [0]).

    Added edit:

    somearray = someelement; 
    

    does not add the element to the array!

    somearray.push(someelement);
    

    does.

    Added edit: just try this instead. Who knows, it might work…

    function imgprocess(text){
     // get all IMG elements below the div
     imgels = text.getElementsByTagName("IMG");
     // filter them somehow
     imgarr = [];
     for (var i=0;i< imgels.length;i++){
       if (imgels[i].src.indexOf(parse(url)) != -1){
        imgarr.push(imgels[i]);
       }
     }
    
     // filter again, could probably be joined into one loop
     imgarres = [];
     for (var p=0; p< imgarr.length; p++){
       if (imgarr[p].parentNode.nodeName=="A"){
         imgarres.push(imgarr[p]);
       }
     }
     // return the first image's src if any
     if (imgarres.length > 0) {
       return imgarres[0].src;
     }
     return null;
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this java code: <script src=http://www.google.com/jsapi></script> <script type=text/javascript> google.load(jquery, 1.2.6); $(a#more).click(function() { $(#info_box).show(blind,
Hey guys, I have this piece of jquery code: <script type=text/javascript > $(function() {
I have a page as below: <head> <script type="text/javascript" src="jquery-1.6.1.js"></script> <script type="text/javascript"> $(document).ready( function()
I have a greasemonkey user script with this single line of code... window.close(); but
I got this javascript code from off the internet. It's a script that changes
I use the jQuery Tools Overlay plugin and I have this code here <script
I have a code like this. <html> <head> <title>Captcha With Refresh Feature</title> <script src=jquery.js
I have this code in jQuery, that I want to reimplement with the prototype
I have this code: chars = #some list try: indx = chars.index(chars) except ValueError:
I have this code that performs an ajax call and loads the results into

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.