I have a set of code
setTimeout(function() {
window.location.reload(true);
if ($scope.attribute.parentAttribute.id) {
angular.element(document.getElementById($scope.attribute.parentAttribute.id)).click();
}
}, 1000);
I am using a timeout, I need to execute that click function after window.location.reload(true);
reload cause by this line. Is it possible?
I have a set of code
setTimeout(function() {
window.location.reload(true);
if ($scope.attribute.parentAttribute.id) {
angular.element(document.getElementById($scope.attribute.parentAttribute.id)).click();
}
}, 1000);
I am using a timeout, I need to execute that click function after window.location.reload(true);
reload cause by this line. Is it possible?
- nope , you are reloading the page before you trigger click – madalinivascu Commented Feb 18, 2016 at 5:34
- 2 Yes, set a flag in local storage, then reload, then test that flag from an onload or DOM ready handler and trigger the click from there. – nnnnnn Commented Feb 18, 2016 at 5:36
- You would need to do it on the load event. – epascarello Commented Feb 18, 2016 at 5:36
- any one can demonstrate please? – vkv Commented Feb 18, 2016 at 5:40
4 Answers
Reset to default 1Define 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./jsref/event_onload.asp
You can call the onload
method from your starting body tag:
<body onload="myFunction()">
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.
$window.onload = function() {
/*do your thing*/
};
You will need to inject $window into your controller or run, etc