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

Commit aa798f1

Browse files
krom-xrlgalfaso
authored andcommitted
fix($location): right button click in firefox
When user click right mouse button on links in firefox, browser goes to link. See http://jsfiddle.net/kromxr/76fKM/12/ Closes #7984
1 parent 5a60302 commit aa798f1

File tree

2 files changed

+35
-1
lines changed

2 files changed

+35
-1
lines changed

src/ng/location.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -837,7 +837,7 @@ function $LocationProvider() {
837837
// TODO(vojta): rewrite link when opening in new tab/window (in legacy browser)
838838
// currently we open nice url link and redirect then
839839

840-
if (!html5Mode.rewriteLinks || event.ctrlKey || event.metaKey || event.which == 2) return;
840+
if (!html5Mode.rewriteLinks || event.ctrlKey || event.metaKey || event.which == 2 || event.button == 2) return;
841841

842842
var elm = jqLite(event.target);
843843

test/ng/locationSpec.js

+34
Original file line numberDiff line numberDiff line change
@@ -1504,6 +1504,40 @@ describe('$location', function() {
15041504
);
15051505
});
15061506

1507+
it('should not rewrite when right click pressed', function() {
1508+
configureService({linkHref: '/a?b=c', html5Mode: true, supportHist: true});
1509+
inject(
1510+
initBrowser(),
1511+
initLocation(),
1512+
function($browser) {
1513+
var rightClick;
1514+
if (document.createEvent) {
1515+
rightClick = document.createEvent('MouseEvents');
1516+
rightClick.initMouseEvent('click', true, true, window, 1, 10, 10, 10, 10, false,
1517+
false, false, false, 2, null);
1518+
1519+
link.dispatchEvent(rightClick);
1520+
} else if (document.createEventObject) { // for IE
1521+
rightClick = document.createEventObject();
1522+
rightClick.type = 'click';
1523+
rightClick.cancelBubble = true;
1524+
rightClick.detail = 1;
1525+
rightClick.screenX = 10;
1526+
rightClick.screenY = 10;
1527+
rightClick.clientX = 10;
1528+
rightClick.clientY = 10;
1529+
rightClick.ctrlKey = false;
1530+
rightClick.altKey = false;
1531+
rightClick.shiftKey = false;
1532+
rightClick.metaKey = false;
1533+
rightClick.button = 2;
1534+
link.fireEvent('onclick', rightClick);
1535+
}
1536+
expectNoRewrite($browser);
1537+
}
1538+
);
1539+
});
1540+
15071541

15081542
it('should not mess up hash urls when clicking on links in hashbang mode', function() {
15091543
var base;

0 commit comments

Comments
 (0)