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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 7, 20262026-06-07T15:08:42+00:00 2026-06-07T15:08:42+00:00

I have written a script that is working perfectly except that I wish to

  • 0

I have written a script that is working perfectly except that I wish to add a timed loop. I am new to Javascript and have pounded my head over this for a few days now, I’m hoping an expert can help me….

Also I only need this to work in FireFox!

This script is pulling data from XML. If nothing is found in the XML then the page displays as normal. If something is found, then it creates a pop-up div displaying the information found and plays an audio file.

The pop-up is simply a div with visibility set to hidden if nothing is found in XML set by calling an external CSS stylesheet. If something is found, then it references a separate stylesheet and plays and audio file and changes the div setting visible to true.

I need to somehow add a loop so that this script keeps checking the XML file every 20-30 seconds and if something is found, it will display my hidden DIV and play the audio alert. This script is fully functional except for the fact that I cant get the script to loop without reloading the page.

I want to keep this in the <head> tag as well.

    <head>
    <script type="text/javascript">

    if (window.XMLHttpRequest)
      {// code for IE7+, Firefox, Chrome, Opera, Safari
      xmlhttp=new XMLHttpRequest();
      }
    else
      {// code for IE6, IE5
      xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
      }
    xmlhttp.open("GET","xml/SearchRequest-11988N.xml",false);
    xmlhttp.send();
    xmlDoc=xmlhttp.responseXML;
    
    xtotaltickets=xmlDoc.getElementsByTagName("issue")[0].getAttributeNode("total");
    totaltickets=xtotaltickets.nodeValue;
    ytotaltickets=parseInt(totaltickets);
    
    if (ytotaltickets<1)
    {
    document.write("<link rel='stylesheet' type='text/css' href='notickets.css'>");
    }
    else
    {
      document.write("<link rel='stylesheet' type='text/css' href='newtickets.css'>");
      var audioElement = document.createElement('audio');
      audioElement.setAttribute('src', 'newticket.ogg');
      audioElement.play();
    }
    
    </script>

Again, I only need this to work in FireFox!

  • 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-06-07T15:08:44+00:00Added an answer on June 7, 2026 at 3:08 pm

    Put your code in a function and use an interval:

    <head>
    <script type="text/javascript">
    
    function refreshXml() {
    
        if (window.XMLHttpRequest)
          {// code for IE7+, Firefox, Chrome, Opera, Safari
          xmlhttp=new XMLHttpRequest();
          }
        else
          {// code for IE6, IE5
          xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
          }
        xmlhttp.open("GET","xml/SearchRequest-11988N.xml",false);
        xmlhttp.send();
        xmlDoc=xmlhttp.responseXML;
    
        xtotaltickets=xmlDoc.getElementsByTagName("issue")[0].getAttributeNode("total");
        totaltickets=xtotaltickets.nodeValue;
        ytotaltickets=parseInt(totaltickets);
    
        if (ytotaltickets<1)
        {
        document.write("<link rel='stylesheet' type='text/css' href='notickets.css'>");
        }
        else
        {
          document.write("<link rel='stylesheet' type='text/css' href='newtickets.css'>");
          var audioElement = document.createElement('audio');
          audioElement.setAttribute('src', 'newticket.ogg');
          audioElement.play();
        }
    }
    
    setInterval(refreshXml, 20000);
    
    </script>
    

    A few other things you need to check:

    • Make sure that the function can be called several times without creating duplicate contents. In particular, you should check if the elements you need are not already there before creating them.

    • To make sure the code run at the right time, you might want to listen to the body onload event. Also consider using jQuery as it will make the code easier to write and maintain.

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

Sidebar

Related Questions

I have written a script that fires a jQuery POST to retrieve data from
So I have a strange question. I have written a script that re-formats data
I have written a Python script that will generate a series of graphs and
I have written a data munging script that is very CPU intensive. It has
I have a written a script in PHP that reads from data from a
I have now written a number of different functions in Google Apps Script that
The script I have written outputs all lines from the file 2 that starts
I have a mechanize script written in python that fills out a web form
I have a script that makes barplots, and opens a new window when 6
I have been working on a build script for a website that we have.

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.