0

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';?

6
  • Where should $auto_close (PHP variable) be declared? Commented Jul 16, 2011 at 16:13
  • To clarify, you just want location.reload to run if $auto_close == 'ok'? Why not just use an if statement? Commented Jul 16, 2011 at 16:14
  • @user603003 in the div/ifrmae that was load. @will that is an other option. Commented Jul 16, 2011 at 16:28
  • Why did you write somebody's solution into the question? Commented Jul 16, 2011 at 18:12
  • @user603003: dolar sign before variable name doesn't necessary mean it's php variable Commented Jul 16, 2011 at 18:17

2 Answers 2

1

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();
Sign up to request clarification or add additional context in comments.

11 Comments

I can't get you're code to work altough it seems the way to go. I have added you're code and how I have implemented it to the first post.
It's not the "first post". It is the question. SO is not a forum, message board or "chat". You'll notice that there is no chronological ordering of answers. Also, the word you're looking for is "your". Does "I can not get you are code to work" make sense? No.
@Tomalak: It is probably because he isn't Englishman as 40% of users on SO (maybe more, maybe less?)
@genesis: Any English dictionary or textbook quite clearly states the difference between "your" and "you're". If unsure, look it up. It only takes a moment, and shows respect to people from whom you're asking help and precious time. (And, more than anything, I get angry when English-speaking people do it, which is very common!)
@Tomalak: I know that your "your" is right. If I would have to look into dictionary everytime I'm not sure with English word, I would have 12 reputation or so
|
0
var i = 1;
if (i == 1) {
    var $auto_close = 'ok';
}
else {
    var $auto_close = 'no';
}

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

3 Comments

The jQuery code is loaded before the variable is set. So this will not work. Any ideas?
I tried that but the javascript code has problems with ($auto_close == 'ok'), I have tried with no luck (<?php echo $auto_close ?> == 'ok')
wait. That $auto_close is php variable?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.