Skip to content

Commit

Permalink
Do not try to navigate to links that are on a different host.
Browse files Browse the repository at this point in the history
  • Loading branch information
Daniel Pupius committed Dec 20, 2011
1 parent ffcbbeb commit 909e36b
Showing 1 changed file with 15 additions and 9 deletions.
24 changes: 15 additions & 9 deletions app.js
Original file line number Diff line number Diff line change
Expand Up @@ -386,16 +386,22 @@ surf.App.prototype.handleDocClick_ = function(e) {

if (el) {
var path = el.pathname + el.search;
surf.log('Link path:', path, '; Base path:', this.basePath_);
if (goog.string.startsWith(path, this.basePath_)) {
path = path.substr(this.basePath_.length);
var navigateFailed = false;
this.navigate(path).addErrback(function(err) { navigateFailed = true; });
// If the navigation failed synchronously then we don't prevent default and let the browser
// handle the click. This would happen for URLs that aren't meant to be managed by the App.
if (!navigateFailed) {
e.preventDefault();
if (el.hostname == window.location.hostname) {
if (goog.string.startsWith(path, this.basePath_)) {
surf.log('Link path:', path, '; Base path:', this.basePath_);
path = path.substr(this.basePath_.length);
var navigateFailed = false;
this.navigate(path).addErrback(function(err) { navigateFailed = true; });
// If the navigation failed synchronously then we don't prevent default and let the browser
// handle the click. This would happen for URLs that aren't meant to be managed by the App.
if (!navigateFailed) {
e.preventDefault();
}
} else {
surf.log('Link clicked outside app\'s base path')
}
} else {
surf.log('Offsite link clicked');
}
}
};
Expand Down

0 comments on commit 909e36b

Please sign in to comment.