I want to reload window after a this custom function finishes:
<script type="text/javascript">
$(document).ready(function(){
setTimeout(function () {
$('#order_form').dolPopupHide({});
}, 3000);
//window.location.reload();
});
</script>
Is there a way I can add the reload to the setTimeout function so it doesn't run until the timeout is over?
I want to reload window after a this custom function finishes:
<script type="text/javascript">
$(document).ready(function(){
setTimeout(function () {
$('#order_form').dolPopupHide({});
}, 3000);
//window.location.reload();
});
</script>
Is there a way I can add the reload to the setTimeout function so it doesn't run until the timeout is over?
Share Improve this question edited Oct 20, 2010 at 14:50 tmartin314 asked Oct 20, 2010 at 14:45 tmartin314tmartin314 4,18110 gold badges42 silver badges60 bronze badges 3-
Did you try
window.location.reload();
? If so, how does that not meet your need? – LarsH Commented Oct 20, 2010 at 14:48 - It reload right away basically. And the page doesn't fully load before it starts. – tmartin314 Commented Oct 20, 2010 at 14:49
- In this context, using document.ready is overkill. setTimeout() already establishes that the code will run later. – jimbo Commented Oct 20, 2010 at 15:28
1 Answer
Reset to default 7reload
needs to be inside your function:
$(document).ready(function(){
setTimeout(function () {
$('#order_form').dolPopupHide({});
window.location.reload();
}, 3000);
});
If you want to conceptually separate the work from the reload, you can do something like this:
$(document).ready(function(){
setTimeout(function () {
doWork();
window.location.reload();
}, 3000);
function doWork() {
$('#order_form').dolPopupHide({});
}
});
Or, to be even more general:
function reloadAfterExec(fn)
return function() {
fn();
window.location.reload();
}
}
$(document).ready(function(){
setTimeout( reloadAfterExec(function() {
$('#order_form').dolPopupHide({});
}), 3000);
});