admin管理员组文章数量:1405603
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
本文标签: javascriptIs that possible to execute a function just after reloadStack Overflow
版权声明:本文标题:javascript - Is that possible to execute a function just after reload...? - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1744313720a2600157.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论