Skip to content Skip to sidebar Skip to footer

Is That Possible To Execute A Function Just After Reload...?

I have a set of code setTimeout(function() { window.location.reload(true); if ($scope.attribute.parentAttribute.id) { angular.element(document.getElementById($scope.at

Solution 1:

Define your handler for the onload event here. This will trigger after a page load (reload is no different):

object.onload=function(){myScript}; //in this case object = window

Source: http://www.w3schools.com/jsref/event_onload.asp

Solution 2:

You can call the onload method from your starting body tag:

<bodyonload="myFunction()">

Solution 3:

Well, once you have called window.location.reload(true); then 1. your page will refresh/reload. 2. all the javascript will reload on the page. 3. all the triggers or callbacks will be destroyed/cancelled.

So in short there is no way to call a function after a reload call is made.

All you can do is call a function at page load time as shown below.

$(function(){
  // this will be executed first when page loads.
});

But there is one glitch with this, this will execute the function whenever the page is loaded.

Solution 4:

$window.onload = function() {
  /*do your thing*/
};

You will need to inject $window into your controller or run, etc

Post a Comment for "Is That Possible To Execute A Function Just After Reload...?"