diff --git a/index.md b/index.md index e8aaccd..4ca25f3 100644 --- a/index.md +++ b/index.md @@ -5,9 +5,7 @@ nav_order: 1 --- - -

If you are not redirected automatically, click here.

- + diff --git a/mainsite/assets/js/direct-link-handler.js b/mainsite/assets/js/direct-link-handler.js deleted file mode 100644 index f410348..0000000 --- a/mainsite/assets/js/direct-link-handler.js +++ /dev/null @@ -1,51 +0,0 @@ -/* Script to allow to direct link a section (header) into a tab (div). */ -function handleDirectLink() { - if (window.location.hash) { - //Format expected is [TAB-ID]_[HEADER-ID-INSIDE-TAB] - let directLocationRef = window.location.hash; - const validationRegex = new RegExp("^#[a-z0-9\-]{1,100}_[a-z0-9\-]{1,100}$"); - //Ensure that the directLink respect the syntax - if (validationRegex.test(directLocationRef)) { - directLocationRef = directLocationRef.substring(1);//Remove the starting dash character - let parts = directLocationRef.split("_"); - let tabLocation = parts[0].substring(4) + "-link";//remove the "-div" prefix and add the "-link" suffix - let headerLocation = parts[1]; - console.debug(`[DirectLinkHandler] Move to tab '${tabLocation}' on header '${headerLocation}'.`); - //Retrieve the target TAB that is a link to a DIV and trigger a click - let tabLink = document.getElementById(tabLocation) - if (typeof tabLink !== "undefined") { - tabLink.click(); - //Now move to the target header that have a link with a href to it - let links = document.querySelectorAll("a"); - let headerLink = null; - links.forEach(function (lnk) { - if (lnk.href.endsWith(`#${headerLocation}`) && headerLink === null) { - headerLink = lnk; - } - }); - if (headerLink !== null) { - setTimeout(() => { headerLink.click(); console.debug(`[DirectLinkHandler] Move performed.`); }, "2000"); - console.debug(`[DirectLinkHandler] Move scheduled.`) - } else { - console.warn(`[DirectLinkHandler] Header tag not found.`); - } - } else { - console.warn(`[DirectLinkHandler] Tab link not found.`); - } - } else { - console.warn("[DirectLinkHandler] Direct link does not match the validation regex.") - } - } -} - -window.addEventListener("load", function () { - const isFirefox = (navigator.userAgent.indexOf("Firefox") !== -1); - if (isFirefox) { - //Fix for issue "github.com/OWASP/secure-headers-project/issues/251" - console.debug(`[DirectLinkHandler] Firefox so delayed call to let the page load.`); - setTimeout(() => { handleDirectLink(); }, "3000"); - } else { - console.debug(`[DirectLinkHandler] Not Firefox so direct call.`); - handleDirectLink(); - } -}); diff --git a/mainsite/assets/js/root-path-redirection-handler.js b/mainsite/assets/js/root-path-redirection-handler.js new file mode 100644 index 0000000..e4c20d3 --- /dev/null +++ b/mainsite/assets/js/root-path-redirection-handler.js @@ -0,0 +1,20 @@ +/* +Script to dynamically handle the redirection to the "/index" path depending on the initial domain requested: +- The GitHub page +- The custom sub domain +*/ +const owaspSubDomain = "secure-headers-project.owasp.org"; +const githubPageSubDomain = "owasp.github.io"; +const sourceDomain = window.location.hostname; + +if (sourceDomain === owaspSubDomain) { + const targetLocation = `https://${owaspSubDomain}/index/`; + console.info(`Visitor come from the custom sub domain so redirect it to '${targetLocation}'...`); + window.location.replace(targetLocation); +} else if (sourceDomain === githubPageSubDomain) { + const targetLocation = `https://${githubPageSubDomain}/secure-headers-project/index/`; + console.info(`Visitor come from the GH page domain so redirect it to '${targetLocation}'...`); + window.location.replace(targetLocation); +} else { + console.error("The source domain is not an expected one so do nothing !"); +} \ No newline at end of file