Skip to content

Commit 4967b2b

Browse files
committed
Do not use pushstate for external links (or links with target)
1 parent 71ac4d0 commit 4967b2b

2 files changed

Lines changed: 23 additions & 12 deletions

File tree

src/u-dom.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -383,7 +383,7 @@ Util.clickableElement = u.ce = function(node, _options) {
383383
}
384384

385385
// meta key pressed
386-
if(event && (event.metaKey || event.ctrlKey)) {
386+
if(event && (event.metaKey || event.ctrlKey || (this._a && this._a.target))) {
387387
window.open(this.url);
388388
}
389389
else {

src/u-history.js

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -10,23 +10,34 @@ Util.History = u.h = new function() {
1010
// create central navigate function
1111
// update hash/url
1212
this.navigate = function(url, node, silent) {
13-
// u.bug("u.h.navigate:" + url + ", " + (node ? u.nodeId(node) : "no node"))
13+
// u.bug("u.h.navigate:" + url, node);
1414

1515
silent = silent || false;
1616

17-
// popstate handling
18-
if(this.popstate) {
19-
history.pushState({}, url, url);
20-
if(!silent) {
21-
this.callback(url);
17+
// Don't navigate external links
18+
if((!url.match(/^http[s]?\:\/\//) || url.match(document.domain)) && (!node || !node._a || !node._a.target)) {
19+
// popstate handling
20+
if(this.popstate) {
21+
history.pushState({}, url, url);
22+
if(!silent) {
23+
this.callback(url);
24+
}
25+
}
26+
// hash handling
27+
else {
28+
if(silent) {
29+
this.next_hash_is_silent = true;
30+
}
31+
location.hash = u.h.getCleanUrl(url);
2232
}
2333
}
24-
// hash handling
2534
else {
26-
if(silent) {
27-
this.next_hash_is_silent = true;
35+
if(!node || !node._a || !node._a.target) {
36+
location.href = url;
37+
}
38+
else {
39+
window.open(this.url);
2840
}
29-
location.hash = u.h.getCleanUrl(url);
3041
}
3142

3243
}
@@ -205,7 +216,7 @@ Util.History = u.h = new function() {
205216
// u.bug("getCleanUrl:" + string + " = " + (string ? string.replace(location.protocol+"//"+document.domain, "").match(/[^#$]+/) : "#error#"));
206217

207218
// remove hash and domain from string before
208-
string = string.replace(location.protocol+"//"+document.domain, "").match(/[^#$]+/)[0];
219+
string = string.replace(location.protocol+"//"+document.domain, "") ? string.replace(location.protocol+"//"+document.domain, "").match(/[^#$]+/)[0] : "/";
209220

210221
if(!levels) {
211222
return string;

0 commit comments

Comments
 (0)