Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

146
Views
Function not running during the load event of the document

I am writing a chrome extension, that has this content_script. I have written 3 functions to be triggered by 2 respective events - The double Click and Load function.

The Double Click event executes the function written for it, but, the load function or onload function are not executing their respective functions.



$("*").dblclick(function(){

    alert("Double Click");     
 
 })
 



document.addEventListener ("onload", myMain, false);

function myMain (evt) {
    alert("On Load");
}


document.addEventListener ("load", myMain, false);

function myMain (evt) {
    alert("Load");
}


about 4 years ago · Juan Pablo Isaza
2 answers
Answer question

0

Using jQuery, here is my understanding of desired events :

$(window).on('load', function() {
    alert('Loaded');
});

$(document).ready(function() {
    alert('Ready');
});

$(window).on('dblclick', function() {
    alert('Double click');
});

The difference between event 'load' and 'ready' is :

  • 'Load' is triggered when your page is completely loaded (images, charts ...).
  • 'Ready' is triggered when your page script's is safe to manipulate.

Just check jQuery documentation for event on document loading : https://api.jquery.com/category/events/document-loading/

There is no event to trigger a document 'onload'.

about 4 years ago · Juan Pablo Isaza Report

0

You can use the DOMContentLoaded event in JS to achieve this. Like this:

window.addEventListener('DOMContentLoaded', myMain);

function myMain (evt) {
    alert("Load");
}

Hope that's how you wanted it to work.

You can check here for more info - DOMContentLoaded Event

about 4 years ago · Juan Pablo Isaza Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!