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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T00:43:29+00:00 2026-05-30T00:43:29+00:00

I have some code (written by another developer) that is doing AJAX page loading

  • 0

I have some code (written by another developer) that is doing AJAX page loading inside of WordPress (e.g. no page reloads) when you click a nav item, AJAX refreshes the primary content area. My problem is that it’s broken in IE7 and I have no idea where to start in terms of debugging.

The original opening lines were

var queue = 0;

$('document').ready(function() {
    window.addEventListener("hashchange", hashChange, false);

    // Define window location variables
    var windowHost = window.location.host,
        windowHash = window.location.hash,
        windowPath = window.location.pathname;

But I changed them to make the addEventListener conditional on the basis of whether that method was present or not. Some research told me that the method is not available in older versions of IE (e.g. 7 in my case). Also, the IE7 debug console was identifying that as an unavailable method, so that’s pretty clear. I rewrote the lines as follows, but the code is still not working:

var queue = 0;

$('document').ready(function() {
    if(window.addEventListener) {
        window.addEventListener("hashchange", hashChange, false);
    }
    else if (window.attachEvent) {
        window.attachEvent("hashchange", hashchange, false);    
    }
    // Define window location variables
    var windowHost = window.location.host,
        windowHash = window.location.hash,
        windowPath = window.location.pathname;

The full original script can be viewed in this pastebin: http://pastebin.com/Jc9ySvrb

  • 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-30T00:43:32+00:00Added an answer on May 30, 2026 at 12:43 am
    • attachEvent requires events to be prefixed with on.
    • You’ve different capitalizations for the method. Change hashchange in attachEvent tohashChange to get the event to work in IE8.
    • Use the suggested implementation to support the hashchange implementation for IE7- and other old browsers.

    I have created a cross-browser implementation, which adds the hashchange feature to browsers, even those who do not support it. The fallback is based on the specification.

    //function hashchange  is assumed to exist. This function will fire on hashchange
    if (!('onhashchange' in window)) {
        var oldHref = location.href;
        setInterval(function() {
            var newHref = location.href;
            if (oldHref !== newHref) {
                var _oldHref = oldHref;
                oldHref = newHref;
                hashChange.call(window, {
                    'type': 'hashchange',
                    'newURL': newHref,
                    'oldURL': _oldHref
                });
            }
        }, 100);
    } else if (window.addEventListener) {
        window.addEventListener("hashchange", hashChange, false);
    }
    else if (window.attachEvent) {
        window.attachEvent("onhashchange", hashChange);    
    }
    

    Note: This code is useful for one hashchange event. If you want to add multiple hashchange handlers, use the following method.
    It defines two functions, addHashChange and removeHashChange. Both methods take a function as an argument.

    (function() {
        if ('onhashchange' in window) {
            if (window.addEventListener) {
                window.addHashChange = function(func, before) {
                    window.addEventListener('hashchange', func, before);
                };
                window.removeHashChange = function(func) {
                    window.removeEventListener('hashchange', func);
                };
                return;
            } else if (window.attachEvent) {
                window.addHashChange = function(func) {
                    window.attachEvent('onhashchange', func);
                };
                window.removeHashChange = function(func) {
                    window.detachEvent('onhashchange', func);
                };
                return;
            }
        }
        var hashChangeFuncs = [];
        var oldHref = location.href;
        window.addHashChange = function(func, before) {
            if (typeof func === 'function')
                hashChangeFuncs[before?'unshift':'push'](func);
        };
        window.removeHashChange = function(func) {
            for (var i=hashChangeFuncs.length-1; i>=0; i--)
                if (hashChangeFuncs[i] === func)
                    hashChangeFuncs.splice(i, 1);
        };
        setInterval(function() {
            var newHref = location.href;
            if (oldHref !== newHref) {
                var _oldHref = oldHref;
                oldHref = newHref;
                for (var i=0; i<hashChangeFuncs.length; i++) {
                    hashChangeFuncs[i].call(window, {
                        'type': 'hashchange',
                        'newURL': newHref,
                        'oldURL': _oldHref
                    });
                }
            }
        }, 100);
    })();
    // Usage, infinitely many times:
    addHashChange(function(e){alert(e.newURL||location.href);});
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have some old code written in C for 16-bit using Borland C++ that
I have written some code to ensure that items on an order are all
I have written some jQuery ajax code where I am sending a request to
I have an application written in C# that invokes some C code as well.
I have a c++ source code that was written in linux/unix environment by some
I have some simple OO code I've written that I'm playing with: //define a
I have written some code in java that will guess a number based on
I have written some C++ code that generates a std::vector. I also have a
I have written some code that makes use of an open source library to
I'm trying to get some code working that a previous developer has written. Yep,

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.