Solved

Javascript Alert - Refresh page after OK clicked

Posted on 2011-03-17
21
7,918 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

 
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

Get 15 Days FREE Full-Featured Trial

Benefit from a mission critical IT monitoring with Monitis Premium or get it FREE for your entry level monitoring needs.
-Over 200,000 users
-More than 300,000 websites monitored
-Used in 197 countries
-Recommended by 98% of users

Question has a verified solution.

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

This article shows how to create and access 2-dimensional arrays in JavaScript.  It includes a tutorial in case you are just trying to "get your head wrapped around" the concept and we'll also look at some useful tips for more advanced programmers. …
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 …
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…

688 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