onload

window.onload does not work in AngularJS

送分小仙女□ 提交于 2019-11-27 17:36:16
问题 This code in a simple HTML file works: <script> function load() { alert("load event detected!"); } window.onload = load; </script> However, if I put it into the index.html file of an AngularJS web app, it does not. Does anybody know why not? 回答1: Call your function with ng-init var app = angular.module('app',[]); app.controller('myController', function($scope){ $scope.load = function () { alert("load event detected!"); } }); <script src="https://ajax.googleapis.com/ajax/libs/angularjs/1.2.23

Add Class to Object on Page Load

﹥>﹥吖頭↗ 提交于 2019-11-27 16:42:14
问题 Basically I want to make this: <li id="about"><a href="#">About</a> Into this when the page loads: <li id="about" class="expand"><a href="#">About</a> I found this thread, but am not so good with javascript and couldn't adapt it: Javascript: Onload if checkbox is checked, change li class 回答1: This should work: window.onload = function() { document.getElementById('about').className = 'expand'; }; Or if you're using jQuery: $(function() { $('#about').addClass('expand'); }); 回答2: I would

jQuery: How to check when all images in an array are loaded?

大憨熊 提交于 2019-11-27 15:54:07
I have an array of images (the exact number of images varies), and when they all load I want some code to execute. I tried this but it doesn't work: myImgArray.load(function(){ alert('loaded'); }); I get 33: Uncaught TypeError: Object [object Object],[object Object],[object Object],[object Object] has no method 'load' I don't think a for loop or something similar would work because the images might, and probably will, load in 'random' order. The only way I know of to do it is to attach a load handler for each image and keep a count of how many have been loaded. When you reach your total, then

Adding multiple onload handlers

你离开我真会死。 提交于 2019-11-27 15:51:02
I have two js files, each one with its own window.onload handler. Depending on how I attach the two onload handlers to the window object I get a different behaviour on the second handler. More specifically, here is my html file: <html> <head> <title>Welcome to our site</title> <script type="text/javascript" src="script1.js"> </script> <script type="text/javascript" src="script2.js"> </script> </head> <body id="pageBody"> <h2 align="center"> <a href="http://www.whatever.com" id="redirect"> Wellcome to our site... c'mon in! </a> </h2> </body> </html> It loads two js files, script1.js and script2

window.onload seems to trigger before the DOM is loaded (JavaScript)

点点圈 提交于 2019-11-27 14:47:29
I am having trouble with the window.onload and document.onload events. Everything I read tells me these will not trigger until the DOM is fully loaded with all its resources, it seems like this isn't happening for me: I tried the following simple page in Chrome 4.1.249.1036 (41514) and IE 8.0.7600.16385 with the same result: both displayed the message "It failed!", indicating that myParagraph is not loaded (and so the DOM seems incomplete). <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd"> <html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en">

Is bubbling available for image load events?

纵饮孤独 提交于 2019-11-27 14:38:32
Can I use: window.addEventListner(); in some way. All my images have a display = 'none' . Once the image has loaded, I want to set display = 'inline' This way I can normalize what is displayed while the image is being downloaded. In this case, I can not pre-load my images. The load / onload event does not bubble ( reference , reference ), so what you're asking for is not possible . You'll have to attach an event handler to each image node, or intercept the event during the capture phase, as suggested in other answers. Use capturing event listener on some DOM node other than window ( body or

Is there a way to have an onload callback after changing window.location.href?

非 Y 不嫁゛ 提交于 2019-11-27 14:38:00
Essentially what I'd like to do is something to the effect of this: window.location.href = "some_location"; window.onload = function() { alert("I'm the new location and I'm loaded!"); }; Is there any way to have a callback when the window's new location is loaded? (The above code doesn't work.) No, you cannot do it the way you want. Loading a new page closes the current document and starts loading a new document. Any code in your current document will no longer be active when the new page starts to load. To have an event handler when the new document loads, you would either need to insert code

Javascript before onload?

橙三吉。 提交于 2019-11-27 14:03:54
Is there any event handler before onLoad/onPageShow? The trouble with onLoad is if there is any change in display, the page will show up without change until it is fully loaded, then the script will run. What is the best way to make sure it will run as soon as possible? If you put Javascript statements (rather than function definitions) inside a <script> tag, they will be executed during page loading - before the onLoad event is fired. <html> <body> <h2>First header</h2> <script type="text/javascript"> alert("Hi, I am here"); document.write("<h3>This is Javascript generated</h3>"); </script>

Setting focus on an HTML input box on page load

99封情书 提交于 2019-11-27 10:56:49
问题 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: <html> <head> <title>Password Protected Page</title> <script type="text/javascript"> function FocusOnInput() { document.getElementById("PasswordInput").focus(); } </script> <style type="text/css" media="screen"> body, html {height: 100%; padding: 0px; margin: 0px;} #outer {width: 100%; height: 100%; overflow:

MVVM load data during or after ViewModel construction?

这一生的挚爱 提交于 2019-11-27 10:51:20
问题 My generic question is as the title states, is it best to load data during ViewModel construction or afterward through some Loaded event handling? I'm guessing the answer is after construction via some Loaded event handling, but I'm wondering how that is most cleanly coordinated between ViewModel and View? Here's more details about my situation and the particular problem I'm trying to solve: I am using the MVVM Light framework as well as Unity for DI. I have some nested Views, each bound to a