Reputation: 21
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
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
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