Questions tagged [onload]

'onload' is a JavaScript event that is run when a document is loaded. Likewise an 'onload' event can be trapped when loading a script.

onload is a JavaScript event that is run when a document is loaded.

2110 questions
370
votes
14 answers

How to execute AngularJS controller function on page load?

Currently I have an Angular.js page that allows searching and displays results. User clicks on a search result, then clicks back button. I want the search results to be displayed again but I can't work out how to trigger the search to execute. …
Duke Dougal
  • 24,359
  • 31
  • 91
  • 123
366
votes
8 answers

How do I call a JavaScript function on page load?

Traditionally, to call a JavaScript function once the page has loaded, you'd add an onload attribute to the body containing a bit of JavaScript (usually only calling a function) When the page has loaded, I want to run some…
palAlaa
  • 9,500
  • 33
  • 107
  • 166
327
votes
11 answers

How to run a function when the page is loaded?

I want to run a function when the page is loaded, but I don’t want to use it in the tag. I have a script that runs if I initialise it in the , like this: function codeAddress() { // code } But I want to…
Claes Gustavsson
  • 5,509
  • 11
  • 50
  • 86
262
votes
10 answers

How to run function in AngularJS controller on document ready?

I have a function within my angular controller, I'd like this function to be run on document ready but I noticed that angular runs it as the dom is created. function myController($scope) { $scope.init = function() { // I'd like…
Shai UI
  • 50,568
  • 73
  • 204
  • 309
241
votes
7 answers

iFrame src change event detection?

Assuming I have no control over the content in the iframe, is there any way that I can detect a src change in it via the parent page? Some sort of onload maybe? My last resort is to do a 1 second interval test if the iframe src is the same as it was…
Matrym
  • 16,643
  • 33
  • 95
  • 140
170
votes
9 answers

Javascript - How to detect if document has loaded (IE 7/Firefox 3)

I want to call a function after a document loads, but the document may or may not have finished loading yet. If it did load, then I can just call the function. If it did NOT load, then I can attach an event listener. I can't add an eventlistener…
Marcos
  • 1,709
  • 2
  • 11
  • 3
145
votes
21 answers

Cannot set property 'innerHTML' of null

Why do I get an error or Uncaught TypeError: Cannot set property 'innerHTML' of null? I thought I understood innerHTML and had it working before.
Joshua W
  • 1,537
  • 2
  • 12
  • 15
139
votes
3 answers

Trying to fire the onload event on script tag

I'm trying to load a set of scripts in order, but the onload event isn't firing for me. var scripts = [ '//cdnjs.cloudflare.com/ajax/libs/less.js/1.3.3/less.min.js', …
chovy
  • 72,281
  • 52
  • 227
  • 295
121
votes
4 answers

Setting focus on an HTML input box on page load

I'm trying to set the default focus on an input box when the page loads (example: google). My page is very simple, yet I can't figure out how to do this. This is what I've got so far: Password Protected Page
Chris
  • 2,905
  • 5
  • 29
  • 30
93
votes
11 answers

jquery get height of iframe content when loaded

I have a Help page, help.php that I am loading inside an iframe in main.php How can I get the height of this page once it has loaded in the iframe? I am asking this because I can't style the height of to iframe to 100% or auto. That's why I think I…
FFish
  • 10,964
  • 34
  • 95
  • 136
84
votes
4 answers

Execute write on doc: It isn't possible to write into a document from an asynchronously-loaded external script unless it is explicitly opened.

I am trying to load a certain script after page load executes, something like this: function downloadJSAtOnload(){ var element = document.createElement("script"); element.src = "scriptSrc"; …
Parijat Kalia
  • 4,929
  • 10
  • 50
  • 77
68
votes
12 answers

JavaScript event window.onload not triggered

I've got the following code in a website: window.onload = resize; window.onresize = resize; function resize(){ heightWithoutHeader = (window.innerHeight - 85) + "px"; document.getElementById("main-table").style.height =…
user321068
68
votes
4 answers

Invoke JSF managed bean action on page load

Is there a way to execute a JSF managed bean action when a page is loaded? If that's relevant, I'm currently using JSF 1.2.
DD.
  • 21,498
  • 52
  • 157
  • 246
61
votes
4 answers

iFrame onload JavaScript event

I have an iFrame, where I want to send a JavaScript command after loading. My current code looks like this: