0

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> 
3
  • Except your code is invalid. There's one }); too much, and a lost $ before window. Commented Jul 22, 2015 at 11:13
  • Have you tried $('body').bind('beforeunload',function(){ //do something }); Commented Jul 22, 2015 at 11:17
  • hi @amarjeetkumar i tried as you suggested as above but no success. Commented Jul 22, 2015 at 11:30

1 Answer 1

2

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.

Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.