Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Javascript Alert - Refresh page after OK clicked

Posted on 2011-03-17
21
Medium Priority
?
8,643 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 83

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
Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
LVL 83

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 83

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 83

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 83

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 83

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 83

Accepted Solution

by:
leakim971 earned 2000 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 83

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 83

Expert Comment

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

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

In my daily work (mainly using ASP.net), I need to write a lot of JavaScript code. One of the most repetitive tasks I do are the jQuery Ajax calls. You know: (CODE) I don't know if for you it's the same, but for me is soooo tedious to write the …
This article discusses how to create an extensible mechanism for linked drop downs.
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…

783 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