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 code: <script type=text/javascript> var maxLength=10; function charLimit(el) { if (el.value.length >
OK i have this code HTML: <html> <head> <script type=text/javascript src=http://code.jquery.com/jquery-1.7.1.min.js> </script> <script type=text/javascript>
I have this code running great in ff, opera and chrome: <script type=text/javascript> $(document).ready(function(){
I have this jQuery code: <script type=text/javascript> $(document).ready(function() { $('.vote_up').click(function() { alert ( test:
i have this code: <!DOCTYPE HTML> <html> <head> <script src=http://ajax.googleapis.com/ajax/libs/dojo/1.7.1/dojo/dojo.js type=text/javascript djConfig=parseOnLoad: true></script> <script
I have this code in userpage.php: <script langauge=JavaScript><!-- function newWindow(fileName,windowName) { msgWindow=window.open(fileName,windowName); } //--></script>
I have this code in a .html.erb file: <script src=http://connect.facebook.net/en_US/all.js#xfbml=1></script> <script> FB.Event.subscribe('edge.create', function(response) {
I have this code: <div id=gll_select> <script> var caffe = $(#caffe).val(); $(#gll_select).load(<?php echo base_url()
I have this code <html> <include jquery> <script> function crea() { var html =
Say I have this code in my page: <script language=javascript> $(document).ready(function() { $(.test).click(function() {

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.