Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angularjs history support for IE6 and IE7

I am using routing in Angularjs for my SPA but I have to support IE7 (and IE8 in IE7 compatibility mode). I want the browser history to still work though. I don't care if I have to use a jQuery plugin.

like image 961
Scotty.NET Avatar asked Jun 20 '13 11:06

Scotty.NET


People also ask

Does Angular support IE8?

The continuous integration server runs all unit tests against IE9, IE10, and IE11. See CircleCI. We do not run tests on IE8 and below. A subset of the AngularJS functionality may work on these browsers, but it is up to you to test and decide whether it works for your particular app.

Does Angular 13 support IE?

Angular 13 does not support Internet Explorer 11. This is a step in the right direction, as dropping IE 11 results in faster app loading times and a smaller bundle size. It also means Angular 13 is free to use modern browser features, such as web animations and CSS variables via native web APIs.

Does Angular work with Internet Explorer?

Supporting Internet Explorer in Angular is easy if you just remember where to find that polyfills. ts file. Finally, take a minute to stop by the core-js GitHub project and give it a star.


1 Answers

I checked through the angular source sniffer.js, location.js and browser.js to check the mechanics of how history is working. In essence if the browser supports history (i.e. $sniffer.history is true) then history api is used, else it simply writes to location.href (or locaiton.replace(url)). Check out $browser.url(url, replace) in browser.js, line 149 for details.

So, if angular is just writing to location then a jquery plugin like Ben Alman's BBQ will pick up this event because it is polling for changes to location.hash. I have successfully got this working in IE8 (in IE7 mode) by simply including Ben's hashchange plugin (a subset of BBQ) and then a minimal event fire and event listening:

$(function () {
  $(window).hashchange(function() {
    // don't delete this empty handler or ie6/7 history won't work.
  });
  // call hashchange on first load
  $(window).hashchange();
});

NOTE: jQuery hashchange (and BBQ) is using deprecated $.browser.msie at line 300 so instead use (document.documentMode != undefined) as suggested in the comments to Ben's blog post.

like image 76
Scotty.NET Avatar answered Sep 27 '22 21:09

Scotty.NET