Cloud Cloud - 1 year ago 63
jQuery Question

How to show popup box even if user change url to another page?

I make a popup dialog with jquery ui and ask a few question to user when they use my site. User must answer that question. If not, user can't access anything on my site.

But the problem is, when users seen popup box and not answer that question then change url to special link or some link of my site in address bar, they don't need to answer that question and can access the other page.

I don't want to access users before they are not answer question. So, I want to show my popup box even if the user change url to another page.

I made this popup question in

page. Here is my code.

....//another code
....//check user session id and show dialog
echo "<div id='dialog'>";
echo "Question"."<br/>";
//select random answer for related question from database
$sql = "...get answer for question...";
$query = .....;
while($row = mysql_fetch_array($query)){
$a_id = $row['id'];
$answer = $row['name'];
echo "<input type='radio' value=\"$a_id\" name='answer' class='answer'>$answer <br/>";
echo "</div>";
width: 500,
modal: true,
position: {my: 'center', at: 'center', of: window, collision:'fit'},
open: function (event, ui) {
create: function(event, ui) {
$("body").css({ overflow: 'hidden' });
buttons: {
Submit: {
text : "Submit",
id : "btn_submit",
click:function() {
......//another code
$( this ).dialog( "close" );
url:'check_question.php',//this is check for user answer is correct or not
data:{..//some data....},
success: function(data){
error: function () {

And I add this file to my home page(index.php) with

Normally, I need to check user is answer or not in every page of my site.
But, its a problem for me because we have a lot of pages.

And I want to coding for checking user changing url and show popup in

So, Is there any way to show my popup box even if user changed the url?

Answer Source

First, I take current page like this $current_page="http://$_SERVER[HTTP_HOST]$_SERVER[REQUEST_URI]";.

And add current page to session and check page form session is same or not, when user request popup.php.

I hope it helps for someone.