4 Replies - 868 Views - Last Post: 26 May 2012 - 07:18 AM Rate Topic: -----

#1 jx2012  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 19-May 12

How to remove all content from a page

Posted 26 May 2012 - 04:32 AM

Hi there,

I couldn't redirect from an iframe to a new page using header( 'Location: newpage.php' ); But I got it by using include('newpage.php') while the page showed some old contents.

1. How can I create a blank initial page and then use a 'include' function?
2. Why header php can't jump out of an iframe?

Thanks for your help!
Is This A Good Question/Topic? 0
  • +

Replies To: How to remove all content from a page

#2 Atli  Icon User is offline

  • Enhance Your Calm
  • member icon

Reputation: 4240
  • View blog
  • Posts: 7,216
  • Joined: 08-June 10

Re: How to remove all content from a page

Posted 26 May 2012 - 04:55 AM

View Postjx2012, on 26 May 2012 - 11:32 AM, said:

1. How can I create a blank initial page and then use a 'include' function?

What do you mean? The include construct just imports PHP code into the current page.

View Postjx2012, on 26 May 2012 - 11:32 AM, said:

2. Why header php can't jump out of an iframe?

Because PHP has no idea that it's running inside an iframe. From it's perspective, an iframe is no different from a normal browser tab. - If you want to mess around with frames, you'll have to use client-side coding to do so.

From what I recall of iframes, you can do window.top to reference the window object of the top-level page, so you should be able to do something along the lines of:
<!-- This would preferably be in the <head> -->
<script type="text/javascript">
function redirectParent(url) {
    window.top.location.href = url;
}
</script>

<!-- And then you can just do -->
<a href="javascript: redirectParent('http://example.com/path/to/page.html');">Redirect</a>


Was This Post Helpful? 0
  • +
  • -

#3 jx2012  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 19-May 12

Re: How to remove all content from a page

Posted 26 May 2012 - 07:05 AM

Hi sorry I didn't say it clearly. Here's what I meant. I created a simple page which had an image uploaded from a php code and a form using an iframe. Please see below.

<?php  echo '<img src="'.$imagefile.'">'; ?>
<iframe src="form.php"></iframe>


form.php
<form action="process.php" method="POST" />
website:<br> <input type="text" name="site" /><br />
<input type="submit" value="Submit" />
</form>


process.php
<?php header( 'Location: http://myhomepage.com' ); ?>


When I click the submit I want the page goes to myhomepage.com But now the msn page is under my image file. How to remove the image from the page <_< ? Thanks.

But now the my home page is under my image file. :helpsmilie: Thanks~~
Was This Post Helpful? 0
  • +
  • -

#4 Atli  Icon User is offline

  • Enhance Your Calm
  • member icon

Reputation: 4240
  • View blog
  • Posts: 7,216
  • Joined: 08-June 10

Re: How to remove all content from a page

Posted 26 May 2012 - 07:08 AM

Like I said, if you want to mess around with frames, you need to use Javascript. PHP can not redirect the top-level frame.

However, PHP can print Javascript. So if you want PHP to redirect your whole page, you simply have it print the Javascript code that would do it.
<?php
$newLocation = "http://example.com/";
echo "<script>window.top.location.href = '{$newLocation}';</script>";
?>


That should cause the whole page to redirect to the $newLocation value.
Was This Post Helpful? 0
  • +
  • -

#5 jx2012  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 24
  • Joined: 19-May 12

Re: How to remove all content from a page

Posted 26 May 2012 - 07:18 AM

Super! It works :^: thanks so much! Yes header works only for non-frame.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1