Skip to content

Commit 11dbf78

Browse files
committed
Check if the page exists before assigning href
1 parent b8c053d commit 11dbf78

File tree

1 file changed

+16
-3
lines changed

1 file changed

+16
-3
lines changed

spec/_static/javascripts/version_dropdown.js

Lines changed: 16 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,22 @@ function add_version_dropdown(json_loc, target_loc, text) {
2121
var a = document.createElement("a");
2222
a.innerHTML = key;
2323
a.title = key;
24-
a.href = target_loc + versions[key] + "/" + path;
25-
console.log('----', a.href);
26-
content.appendChild(a);
24+
var url = target_loc + versions[key];
25+
var http = new XMLHttpRequest();
26+
http.open('HEAD', url + "/" + path );
27+
http.onreadystatechange = function() {
28+
if (this.readyState == this.DONE) {
29+
callback(this.status != 404);
30+
if(this.status != 404 ){
31+
a.href = url + "/" + path;
32+
}
33+
else {
34+
a.href = url;
35+
}
36+
content.appendChild(a);
37+
}
38+
};
39+
http.send();
2740
}
2841
}
2942
}).done(function() {

0 commit comments

Comments
 (0)