Error message

The spam filter installed on this site is currently unavailable. Per site policy, we are unable to accept new submissions until that problem is resolved. Please try resubmitting the form in a couple of minutes.

JavaScript Regular Expressions in Internet Explorer

Category: 

So today Internet Explorer again decided to be totally awesome...

I have a simple javascript regular expression that extracts the Drupal 'page' variable from a link that was clicked:

<a href="/code?page=1" id="tf_example_link">next page</a>
$('a#tf_example_link').click(function () {
  var page = /[\?&]+page=([0-9]+)[\?&]?/($(this).attr('href'));
  alert(page); // alert output: 1
});

This works in all browsers, except....... drum roll.............. Internet Explorer! Surprised? Probably not.

Here is equivalent (yet not as elegant) code that will work in IE:

var regexp = /[\?&]+page=([0-9]+)[\?&]?/;
var page = regexp.exec(($(this).attr('href')));
alert(page); // alert output: 1

Add new comment