0

I have a web app where, after a function is carried out by the user they are given a notification which tells if they were successful or not for whatever they did. For every function I've declared the variable $message which echos out as the notification using the following code:

if(isset($message)) {
 echo "<div id='notification'>" . $message . "</div>"

My problem is that, for styling purposes, this app needs to be inside an iframe inside index.php. The notification is styled position: absolute; right: 0 but obviously it is confined within the frame whereas it needs to be outside the frame and so it flows with the design (executes outside the frame).

I tried using the same code above with php's include but I get no output whatsoever, presumably because isset returns NULL since the function isn't executed within index.php.

So my question is, can I either capture the php output and echo it in index.php or run an iframe element ( #notification ) out side of it's frame.

Thanks. If anyone know's of another work around that'd be welcome. I'm also relatively new to PHP so explanations are welcome too.

6
  • I've tried using include to add the app with php in index.php Jan 13, 2013 at 19:55
  • @case1352 any idea what i could do. Jan 13, 2013 at 20:06
  • You can make another call to the script with a different parameter set (messages_only=true for example) and display messages separately for the cost of executing script twice.
    – AKS
    Jan 13, 2013 at 20:08
  • @AyeshK can you explain a bit more. I'm not that great with php Jan 13, 2013 at 20:17
  • Why don't you simply include the content from the iframe into index.php ?
    – tftd
    Jan 13, 2013 at 20:18

2 Answers 2

0
<iframe src="put_here_your_iframe_url.php?msg=<?echo urlencode($message);?>" ></iframe>

and in iframe

you'll show the message with this line:

echo 'Message: '.urldecode($_GET['msg']);
0

It isn't possible to position content outside of an iframe bounding box.

If both iframe content and its parent page are hosted under the same domain you could pass the message from iframe to the parent page using simple JavaScript.

Parent page:

<div id="msg"></div>

<script>
var displayNotification = function( message ){ document.getElementById('msg').innerHTML = message; }
</script>

Change in your PHP script

if(isset($message)) {
echo "<script> top.displayNotification(" . $message . ");</script>";

Your Answer

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

Not the answer you're looking for? Browse other questions tagged or ask your own question.