Since the order is:
-first parse PHP and send HTML to client
-then client runs Javascript that is in HTML
to do what you want will take multiple requests.
What you could do is:
-Load an HTML page that uses Ajax (a second request) to send the javascript variable to the server. The server then responds to the Ajax request with XML, and javascript should already know what to do with the answer.
-Load an HTML page that directly refreshes itsself, but sends along the javascript variable as a request variable (POST or GET). Something like:
<?php
if (!isset($_REQUEST['iframe']) { // php checks if this it got the variable
// it is not given yet, so let javascript refresh and give the variable
?>
<script>
var url = window.location.href.split('#')[0];
var devider = url.indexOf('?') == -1 ? '?' : '&';
var hash = typeof window.location.href.split('#')[1] == 'undefined' ? '' : '#' + window.location.href.split('#')[1];
if ( window.self === window.top ) {
window.location.href = url + devider + 'iframe=0' + hash;
} else {
window.location.href = url + devider + 'iframe=1' + hash;
}
</script>
<?php
} else {
// it is given to php, lets do something with it...
if ($_REQUEST['iframe'] == 1) {
// ok, we're in an iframe. So what do you want to do?
} else {
// ok, we're not in an iframe. So what do you want to do?
}
}
?>