Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

IE9 (and 8?) reloads page on link with ng-click if $location is injected #1179

Closed
mna opened this issue Jul 19, 2012 · 3 comments
Closed

IE9 (and 8?) reloads page on link with ng-click if $location is injected #1179

mna opened this issue Jul 19, 2012 · 3 comments

Comments

@mna
Copy link

mna commented Jul 19, 2012

As discussed here on google groups, Leo Cavalcante points out that when the $location dependency is injected, IE8-9 acts strangely and somehow reloads the page, instead of preventing the default action as is expected on a click on an anchor with the ng-click directive. I forked his fiddle and made another one which shows the problem in a more obvious way:

http://jsfiddle.net/Tg2Hs/5/

On initial run, the value in the textbox is 'initial', then after the click on the link it gets changed to 'test', but is reverted back to 'initial' automatically because of this bug. If we remove the $location dependency and re-run the fiddle, it works as expected. I don't have IE8, but I have this problem on IE9 / Win7.

Hopefully this is not a duplicate, I did check the issues marked as bugs and did not find this.

Martin

EDIT: This is with AngularJS 1.0.1 by the way, as can be seen in the fiddle.

@mna
Copy link
Author

mna commented Jul 21, 2012

Workaround in the mean time: send $event as argument to the ng-click method, and call $event.preventDefault() manually. Seems to work, see this fiddle:

http://jsfiddle.net/Tg2Hs/8/

@co-dh
Copy link

co-dh commented Nov 25, 2012

My workaround is :
For me, the problem is : when you use href='#' or href='javascript:void(0)' in an anchor,
$browser.url() has an # or ? at the end. by remove the # or ?, it will not trigger the url change event.

diff -r 0c10cf25fe41 htdocs/js/angular.js
--- a/htdocs/js/angular.js  Sat Nov 24 09:46:30 2012 -0500
+++ b/htdocs/js/angular.js  Sun Nov 25 10:06:01 2012 -0500
@@ -5434,7 +5434,11 @@
     var changeCounter = 0;
     $rootScope.$watch(function $locationWatch() {
       var oldUrl = $browser.url();
-
+      if (! isNaN(msie))
+      {
+        // remove last # or ? in oldUrl. 
+        oldUrl = oldUrl.replace(/\?$/, '').replace(/#$/, '')
+      }
       if (!changeCounter || oldUrl != $location.absUrl()) {
         changeCounter++;
         $rootScope.$evalAsync(function() {

@btford btford closed this as completed Aug 24, 2013
@btford
Copy link
Contributor

btford commented Aug 24, 2013

As part of our effort to clean out old issues, this issue is being automatically closed since it has been inactivite for over two months.

Please try the newest versions of Angular (1.0.8 and 1.2.0-rc.1), and if the issue persists, comment below so we can discuss it.

Thanks!

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants