How we run JavaScript code when page refresh but function still run. I want to run this JavaScript code
<script>
function abc(){
}
</script>
How we run JavaScript code when page refresh but function still run. I want to run this JavaScript code
<script>
function abc(){
}
</script>
You can get function called/executed on page load or refresh.
function abc(){
// enter your code
}
With JQuery:
$(function(){
abc();
});
jQuery using .ready()
method:
$(document).ready(function() {
abc();
});
With Normal JS
(function(){
abc();
})();
function abc(){
console.log(Date.now())
}
$(function(){
abc();
});
$(document).ready(function() {
abc();
});
(function(){
abc();
})();
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
You can use ServiceWorkers to be able to run things in background (after refresh, when offline, or when your browser/tab is closed).