Jump to content

Recommended Posts

Is it possible to change the page of the parent of an iframe?

 

For example if I have a main webpage: main.php and inside I have an iframe who's current page is intheframe.php, is it possible to click a button in intheframe.php and have the parent (main.php) page change?

well, I tried that and it didn't work and I tried parent.window.location = 'page.php';

that didn't work either

 

I used some javascript to get the job done but I would rather use php in the case someone  doesn't have java installed. 

 

Here is the code I used:

<script type="text/javascript">
<!--
parent.window.location = "http://salvagedrides.com/usa/home.php?innerframe=account"
//-->
</script>

 

Now here is another one, I need to change what is inside another iframe from a different iframe, both childs of the same parent.  Any ideas on that one?

 

You can use the same logic:

//put this on your parent page
function chage(url)
{
var iframe = document.getElementById('iframe');
iframe.src = url;
}
//then on the iframe
window.parent.window.change(http://www.google.com);

 

Something like that anwyay. Feel free to play around with it a bit.

 

but I would rather use php

And you can't use php for something like this, as it's server side.

Iframes are now a bit outdated but can still work.

 

You could use something like this (I dont guarantee it works):

<a href="somepage.htm" onclick="window.parent.window.change(somepage.htm);">Click here to go to somepage</a>

 

Also, if you are using an iframe to change a parent, then the iframe will disappear.

 

Here is an example I found off the web showing how to use the parent page to change the iframe:

 

Parent window's content:

    <b>iframe starts here</b><br><br>
    <iframe src='iframe1.html'></iframe>
    
    <br><br>
    <b>iframe ends here</b>

    <script type="text/javascript">
        function change_parent_url(url)
        {
    document.location=url;
        }		
    </script>

Iframe's content:

    IFRAME content<br><br>

     <a href="javascript:parent.change_parent_url('http://yahoo.com');"> 
Click here to change parent URL </a>

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.