0

I'm making a bookmarklet that adds a <script> link to a javascript file on my website. Then it will run the function. I can't get it to run, though. window.onload doesn't work, as the page has already loaded when the link is added. I'm wondering if there's something that will trigger a function when the javascript is linked. New Update: I found a solution. I used setTimeout().

setTimeout(function() {
//code here
}, 0);

Putting 0 does seem to work. Thanks for the help, though!

1 Answers1

0

There is not a trigger when javascript is linked, fastest trigger to execute your code is, window.onload will wait load to finish so it's "slower", also see this post may be helpfull onload vs ready

$( document ).ready(function() {
    console.log( "ready!" );
});
rmontanodev
  • 139
  • 2
  • Do you think void function() {//script here}; would work? This function is just a series of if...then statements that trigger other functions. It doesn't have to return anything. Also, I'm kinda new to the void operator, so I might be using it wrong. Also, I'd love to upvote your post, but I can't because I'm new here. –  Mar 27 '20 at 14:09
  • In javascript you don't need to put void function, functions can return a value or not you don't need to necessary type it. – rmontanodev Mar 27 '20 at 14:27