Reputation: 1799
i am very new to jquery, so any advise and help will be much appreciated.
The aim is: when a user refreshes a page the below jquery action should take place but i am unsure how to use window.location.reload in the code - any advise help would be much appreciated
<script>
$(document).ready(function () {
$ window.location.reload(true);
$(".message-content" ).removeClass( "hide" )
$(".unlimited-content" ).addClass( "hide" )
$(".basic-content" ).addClass( "hide" )
$("#paypal_express_checkout input:first").val("10165346");
});
});
</script>
i decided to try the below, it partially works as it displays the jquery action but then it does an automatics refresh which does not display the result of the jquery code to be excuted
<script>
$(window).on('beforeunload', function(){
$(".message-content" ).removeClass( "hide" )
$(".unlimited-content" ).addClass( "hide" )
$(".basic-content" ).addClass( "hide" )
$("#paypal_express_checkout input:first").val("10165346");
});
</script>
Upvotes: 0
Views: 710
Reputation: 628
If there's only a single page, you don't have to bother using
$window.location.reload. Whenever a page is refreshed,
$document.ready()is invoked automatically.
If there're two pages and you want to reload the first page whenever the second page is refreshed, simply use
$document.ready({ $firstPageWindowName.location.reload() });from the second page
<script>
tag.
Upvotes: 2