Dania AlBorene
Dania AlBorene

Reputation: 21

Cannot catch Chrome window.location.href in Chrome

Cannot catch Chrome window.location.href in Chrome even the location not changed

try {
     window.location.href = 'file://folder/whatever/';
} catch (err) {
     alert("Error hit!");
}

Upvotes: 0

Views: 2283

Answers (2)

doniyor2109
doniyor2109

Reputation: 624

It seems that chrome does not throw exception when the protocol is file. But if you really want to throw exception:

var redirect=function(url){if (/^file/.test(url)){throw 'some exception'} window.location.href=url}

try{
   redirect('file://some/path');
} catch(e){
  alert(e);
}

Upvotes: 2

guest271314
guest271314

Reputation: 1

Try with three forward slashes at file: protocol

try {
     // `file://` : protocol, `/folder` : top level directory
     // `/whatever/` : folder
     window.location.href = "file:///folder/whatever/";
} catch (err) {
     alert("Error hit!");
}

Upvotes: 0

Related Questions