开发者

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 clos开发者_运维技巧e 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';?


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();


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

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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜