Solved

Javascript Alert - Refresh page after OK clicked

Posted on 2011-03-17
21
6,984 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
 
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
How to run any project with ease

Manage projects of all sizes how you want. Great for personal to-do lists, project milestones, team priorities and launch plans.
- Combine task lists, docs, spreadsheets, and chat in one
- View and edit from mobile/offline
- Cut down on emails

 
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

What Security Threats Are You Missing?

Enhance your security with threat intelligence from the web. Get trending threat insights on hackers, exploits, and suspicious IP addresses delivered to your inbox with our free Cyber Daily.

Join & Write a Comment

Today I would like to talk about localizing (Internationalization) JavaScript applications. Introduction When creating an application that is going to be used by many people around the globe, it is important to remember that not everyone speak…
When you need to keep track of a simple list of numbers or strings, the Array object is your most direct tool.  As we saw in my earlier EE Article (http://www.experts-exchange.com/A_3488.html), typical array handling might look like this: (CODE) B…
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…

707 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

Need Help in Real-Time?

Connect with top rated Experts

20 Experts available now in Live!

Get 1:1 Help Now