1

I am trying to get my little js script to run once the entire dom or content of the aspx is loaded.

I have loaded the below:

JavaScript that executes after page load

and they still fire everytime an element is loaded.

I also tried

 document.addEventListener("DOMContentLoaded", function () {
            //Me Script!
        });

This kinda works it loades the entire page before running the script for the number of times per element.

Or if there is a work around for my script so that it still forces what I want. Which is just add two slashes to my chosen links. ie file://///jobs/year/etc

            if (isFirefox || isChrome) {
                //You can use what ever to detect links, you can do it by tag and get every link. 
                var linkmodify = document.getElementsByClassName("fa-folder-open");
                for (var i = 0; i < linkmodify.length; i++) {
                    var replacementLink = "";
                    link = linkmodify[i].href;
                    for (var j = 0; j < link.length; j++) {
                        if (j == 5) {
                            replacementLink += '//';
                        }
                        replacementLink += link[j];
                    }
                    linkmodify[i].href = replacementLink;
                }
            }

Currently the links only have the standard three slashes.

Achmann
  • 196
  • 1
  • 11

1 Answers1

0
var haveIDoneMyStuff = false;    
var myDOMLoadHandler = function(){
    if (!haveIDoneMyStuff){
        doMyStuff();
        haveIDoneMyStuff = true;
    }
}

document.addEventListener('DOMContentLoaded', myDOMLoadHandler);
Andrew Ridgway
  • 574
  • 2
  • 9
  • Unfortunatly didn't work, on an interesting not now it is consistently adding two extra slashes per element on the page `file:///////////////////////////////////////JOBS/2016/16105/` – Achmann Nov 02 '18 at 03:49
  • See edited code. It's not pretty, but it will at least ensure that the code is running exactly once. – Andrew Ridgway Nov 02 '18 at 05:52