Solved

Javascript Alert - Refresh page after OK clicked

Posted on 2011-03-17
21
7,320 Views
Last Modified: 2012-05-11
Hi all,

I am using JQuery Alert messages ... see here: http://abeautifulsite.net/blog/2008/12/jquery-alert-dialogs/#usage

I am trying to create a callback so when I click on the OK button it will refresh the page.

Here's what I tried:

jAlert('Thank You.', 'Title Here ',function(){ window.location.reload(); });
      return false;

The above doesn't work so I'm doing something wrong?

This on it's own: <script>history.go(0)</script> works well but I need to integrate it so that it does the reload after I click OK button.

Any ideas please?

Thanks


0
Comment
Question by:error77
  • 9
  • 9
  • 3
21 Comments
 
LVL 82

Expert Comment

by:leakim971
ID: 35156603
work fine for me :


<html><head>
		<script src="http://labs.abeautifulsite.net/projects/js/jquery/alerts/demo/jquery.js" type="text/javascript"></script> 
		<script src="http://labs.abeautifulsite.net/projects/js/jquery/alerts/demo/jquery.ui.draggable.js" type="text/javascript"></script> 
		<script src="http://labs.abeautifulsite.net/projects/js/jquery/alerts/demo/jquery.alerts.js" type="text/javascript"></script> 
		<link href="http://labs.abeautifulsite.net/projects/js/jquery/alerts/demo/jquery.alerts.css" rel="stylesheet" type="text/css" media="screen" /> 
<script>
	$(document).ready(function() {
		jAlert('Thank You.', 'Title Here ',function(){ window.location.reload(); });
	})
</script></head><body>
</body></html>

Open in new window

0
 
LVL 4

Expert Comment

by:Finec
ID: 35156665
To refresh, try to use this:

location.reload(true)

Open in new window


I tried this, and it's worked:

$("#confirm_button").click( function() {
	jConfirm('Can you confirm this?', 'Confirmation Dialog', function() {
		location.reload(true);
	});
	return false;
});

Open in new window

0
 

Author Comment

by:error77
ID: 35156831
None of them are reloading the page.

Only <script>history.go(0)</script> works for me.

The page is inside a frame ... just realised that :o/

Any ideas?

Thanks again
0
Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

 
LVL 82

Expert Comment

by:leakim971
ID: 35156871
Try : window.opener.location instead location
0
 
LVL 4

Expert Comment

by:Finec
ID: 35156979
Try this:

parent.document.location.reload(true);

Open in new window

0
 

Author Comment

by:error77
ID: 35157006
Tried:

1. window.opener.location.reload(true);

2. parent.document.location.reload(true);

None worked
0
 
LVL 4

Expert Comment

by:Finec
ID: 35157024
Can you show it online?
0
 
LVL 82

Expert Comment

by:leakim971
ID: 35157073
the pages are not on the same domain or don't use the same protocol ?
0
 

Author Comment

by:error77
ID: 35157075
It's on internal servers so there's no outside access possible. sorry :o/
0
 

Author Comment

by:error77
ID: 35157306
I have an idea but don't know how to inplement it.

If I do this:

function myFunc() { jAlert('Thank You.', 'Title Here ',function(){ alert('button was clicked'); });
      return 'yes';
      //then
      if 'yes' {
      history.go(0);
      }


Does something like that make sense?


     
0
 
LVL 82

Expert Comment

by:leakim971
ID: 35157382
I don't know why you return something... so not really..
0
 

Author Comment

by:error77
ID: 35157407
I just want to call the history.go(0); only when the click button is hit .. know what I mean?
0
 
LVL 82

Expert Comment

by:leakim971
ID: 35157437
before using jAlert try simple one :

function myFunc() {
    history.go(0);
}

Open in new window


of

<input type="button" onclick="history.go(0);" value="click" />

Open in new window


do it work just with this ?


   
0
 

Author Comment

by:error77
ID: 35157712
Yes, the inline onclick="history.go(0);" worked but I don't want the page reloaded until I click OK ... know what I mean?

0
 
LVL 82

Expert Comment

by:leakim971
ID: 35157749
>Yes, the inline onclick="history.go(0);" worked
Good

>but I don't want the page reloaded until I click OK ... know what I mean?
It work like this with my code HERE
0
 

Author Comment

by:error77
ID: 35157846
I did try that code and it didn't work for me.

Also, the message would appared on every startup.

But mainly window.location.reload(); didn't reload my whole page.
0
 
LVL 82

Accepted Solution

by:
leakim971 earned 500 total points
ID: 35157889
>Also, the message would appared on every startup.

This is a reload so you get it each page reload
This code say : each time the page is fully loaded, display the message and reload :

      $(document).ready(function() {
            jAlert('Thank You.', 'Title Here ',function(){ window.location.reload(); });
      })

with a click :


$(document).ready(function() {
           $("#mybutton").live("click", function() {
		jAlert('Thank You.', 'Title Here ',function(){ window.location.reload(); });
           })
	})

with somewhere in the page :

<input type="button" id="mybutton" value="click to reload" />

Open in new window

0
 

Author Comment

by:error77
ID: 35158055
I've tried your code and it's not working here. It does refresh but not the whole page. And it does it automatically without me clicking the OK button, which is making the alert disappear on it's own.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 35158069
post your page code (right click on the browser, choose view source, and post it here)
0
 

Author Closing Comment

by:error77
ID: 35158125
Will use this right now as I need to get it done. Thanks for your time.
0
 
LVL 82

Expert Comment

by:leakim971
ID: 35158160
You're very welcome! Thanks for the points!
0

Featured Post

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Avoid defining the variables in the global scope; trying to define them in a local function scope. Because:   • Look-up is performed every time a variable is accessed.   • Variables are resolved backwards from most specific to least specific scope…
The task A number given should be formatted for easy reading by separating digits into triads. Format must be made inline via JavaScript, i.e., frameworks / functions are not welcome. So let’s take a number like this “12345678.91¿ and format i…
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

803 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question