Muiter
Muiter

Reputation: 1520

location.reload() when variable is set

I have this code:

//Close Popups and Fade Layer
//$('a.close, #fade').live('click', function() { //When clicking on the close or fade layer...
$('a.close').live('click', function() { //When clicking on the close...
    $('#fade , .popup_block').fadeOut(function() {
        $('#fade, a.close').remove();  //fade them both out
        location.reload(); // reload page
    });
    return false;

Is there an way so location.reload(); will only be fired if an variable is set the page like $auto_close = 'ok';?

Upvotes: 0

Views: 738

Answers (2)

ipr101
ipr101

Reputation: 24236

You could assign the value of $auto_close to a hidden field on the page and then check that field before doing the reload.

The PHP code/HTML mark-up would look something like this (pseudo code alert - this might not be the correct PHP syntax)

<input type="hidden" id="hiddenfieldforauto_close" value="<%=$auto_close%>">

This will then allow the jQuery code to check the vale of the '$auto_close' variable in client side code -

if ($("#hiddenfieldforauto_close").val() == 'ok') location.reload();

Upvotes: 1

genesis
genesis

Reputation: 50982

var i = 1;
if (i == 1) {
    var $auto_close = 'ok';
}
else {
    var $auto_close = 'no';
}

if ($auto_close == 'ok') {
    location.reload();
}

Upvotes: 0

Related Questions