Javascript Alert - Refresh page after OK clicked

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


error77Asked:
Who is Participating?
 
leakim971PluritechnicianCommented:
>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
 
leakim971PluritechnicianCommented:
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
 
FinecCommented:
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
Cloud Class® Course: Ruby Fundamentals

This course will introduce you to Ruby, as well as teach you about classes, methods, variables, data structures, loops, enumerable methods, and finishing touches.

 
error77Author Commented:
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
 
leakim971PluritechnicianCommented:
Try : window.opener.location instead location
0
 
FinecCommented:
Try this:

parent.document.location.reload(true);

Open in new window

0
 
error77Author Commented:
Tried:

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

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

None worked
0
 
FinecCommented:
Can you show it online?
0
 
leakim971PluritechnicianCommented:
the pages are not on the same domain or don't use the same protocol ?
0
 
error77Author Commented:
It's on internal servers so there's no outside access possible. sorry :o/
0
 
error77Author Commented:
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
 
leakim971PluritechnicianCommented:
I don't know why you return something... so not really..
0
 
error77Author Commented:
I just want to call the history.go(0); only when the click button is hit .. know what I mean?
0
 
leakim971PluritechnicianCommented:
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
 
error77Author Commented:
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
 
leakim971PluritechnicianCommented:
>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
 
error77Author Commented:
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
 
error77Author Commented:
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
 
leakim971PluritechnicianCommented:
post your page code (right click on the browser, choose view source, and post it here)
0
 
error77Author Commented:
Will use this right now as I need to get it done. Thanks for your time.
0
 
leakim971PluritechnicianCommented:
You're very welcome! Thanks for the points!
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.