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

Commit 2c69a67

Browse files
committed
fix($location): prevent navigation when event isDefaultPrevented
1 parent c575a56 commit 2c69a67

File tree

3 files changed

+9
-2
lines changed

3 files changed

+9
-2
lines changed

src/jqLite.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ function createEventHandler(element, events) {
560560
}
561561

562562
event.isDefaultPrevented = function() {
563-
return event.defaultPrevented;
563+
return event.defaultPrevented || event.returnValue == false;
564564
};
565565

566566
forEach(events[type || event.type], function(fn) {

src/ng/location.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ function $LocationProvider(){
527527
var absHref = elm.prop('href');
528528
var rewrittenUrl = $location.$$rewrite(absHref);
529529

530-
if (absHref && !elm.attr('target') && rewrittenUrl) {
530+
if (absHref && !elm.attr('target') && rewrittenUrl && !event.isDefaultPrevented()) {
531531
event.preventDefault();
532532
if (rewrittenUrl != $browser.url()) {
533533
// update location manually

test/ng/locationSpec.js

+7
Original file line numberDiff line numberDiff line change
@@ -835,6 +835,12 @@ describe('$location', function() {
835835
jqLite(link).attr('href', 'http://host.com/base/');
836836
browserTrigger(link, 'click');
837837
expectRewriteTo($browser, 'http://host.com/base/');
838+
839+
jqLite(link).
840+
attr('href', 'http://host.com/base/foo').
841+
bind('click', function(e) { e.preventDefault(); });
842+
browserTrigger(link, 'click');
843+
expect($browser.url()).toBe('http://host.com/base/');
838844
}
839845
);
840846
});
@@ -1372,6 +1378,7 @@ describe('$location', function() {
13721378
expect(location.$$rewrite('http://other')).toEqual(undefined);
13731379
expect(location.$$rewrite('http://server/pre/')).toEqual('http://server/pre/');
13741380
expect(location.$$rewrite('http://server/pre/#otherPath')).toEqual('http://server/pre/#otherPath');
1381+
expect(location.$$rewrite('javascript:void(0)')).toEqual(undefined);
13751382
});
13761383
});
13771384

0 commit comments

Comments
 (0)