Supress prev and next links when inside iframe
This commit is contained in:
parent
7504f32ce7
commit
f885ab684e
@ -1,4 +1,6 @@
|
|||||||
window.onload = function(){doNavs();}
|
document.addEventListener("DOMContentLoaded", () => {
|
||||||
|
doNavs(); // Your initialization code
|
||||||
|
});
|
||||||
//function openTab(event, tabId){
|
//function openTab(event, tabId){
|
||||||
//// Get all elements with class="tab-content" and hide them
|
//// Get all elements with class="tab-content" and hide them
|
||||||
//const tabContents = document.querySelectorAll('.tab-content');
|
//const tabContents = document.querySelectorAll('.tab-content');
|
||||||
@ -12,24 +14,44 @@ window.onload = function(){doNavs();}
|
|||||||
//document.getElementById(tabId).classList.add('tab-content-active');
|
//document.getElementById(tabId).classList.add('tab-content-active');
|
||||||
//event.target.classList.add('tab-active');}
|
//event.target.classList.add('tab-active');}
|
||||||
|
|
||||||
function LinkCheck(url){
|
//function LinkCheck(url){
|
||||||
var http = new XMLHttpRequest();
|
//var http = new XMLHttpRequest();
|
||||||
http.open('HEAD', url, false);
|
//http.open('HEAD', url, false);
|
||||||
http.send();
|
//http.send();
|
||||||
return http.status!=404;
|
//return http.status!=404;
|
||||||
|
//}
|
||||||
|
|
||||||
|
async function LinkCheck(url) {
|
||||||
|
//Not allowed by CSP rules.
|
||||||
|
//try {
|
||||||
|
//const response = await fetch(url, { mode: "no-cors" });
|
||||||
|
//return response.ok; // Returns true if the resource exists
|
||||||
|
//} catch (error) {
|
||||||
|
//console.error("Error checking link:", error);
|
||||||
|
//return false;
|
||||||
|
//}
|
||||||
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
function doNavs() {
|
function doNavs() {
|
||||||
|
const isInIframe = window.self !== window.top;
|
||||||
var aTags = document.getElementsByTagName('a'),
|
var aTags = document.getElementsByTagName('a'),
|
||||||
atl = aTags.length,i;
|
atl = aTags.length,i;
|
||||||
for (i = 0; i < atl; i++) {
|
for (i = 0; i < atl; i++) {
|
||||||
if (aTags[i].innerText == "Previous") {
|
if (aTags[i].innerText == "Previous") {
|
||||||
if (!LinkCheck(aTags[i].href)) {
|
if (isInIframe){ //!LinkCheck(aTags[i].href)) {
|
||||||
aTags[i].style.visibility = "hidden";
|
aTags[i].style.visibility = "hidden";
|
||||||
} else {
|
} else {
|
||||||
aTags[i].style.visibility = "visible";
|
aTags[i].style.visibility = "visible";
|
||||||
}
|
}
|
||||||
} else if (aTags[i].innerText == "Next") {
|
} else if (aTags[i].innerText == "Next") {
|
||||||
if (!LinkCheck(aTags[i].href)) {
|
if (isInIframe){ //!LinkCheck(aTags[i].href)) {
|
||||||
|
aTags[i].style.visibility = "hidden";
|
||||||
|
} else {
|
||||||
|
aTags[i].style.visibility = "visible";
|
||||||
|
}
|
||||||
|
} else if (aTags[i].innerText == "Index of files") {
|
||||||
|
if (isInIframe){ //!LinkCheck(aTags[i].href)) {
|
||||||
aTags[i].style.visibility = "hidden";
|
aTags[i].style.visibility = "hidden";
|
||||||
} else {
|
} else {
|
||||||
aTags[i].style.visibility = "visible";
|
aTags[i].style.visibility = "visible";
|
||||||
|
Loading…
x
Reference in New Issue
Block a user