...

View Full Version : Iframes and parent window handling....



KlownCoder
03-17-2005, 06:22 PM
Here is my problem. The main layout of the site contains the navigation and the banners. Under that is a table that contains an iframe where all content is displayed. I don't want someone to be able to pull up an html page that under normal circumstances would show in the iframe without the parent. I hope I said that right. Basically I don't want pages to be viewable without my navigation and banners. Is there a way through javascript to check to see if the parent windows is there, and if not go to the main htm page and insert the page in the main iframe....

I attempted to search the forum for an answer and could not find one. Please excuse me if someone has already covered this issue.

Mr J
03-17-2005, 07:39 PM
Please try the following placed in the page in the iframe


<script type="text/javascript" language="javascript">
<!--
if(document.location == top.document.location)
document.location = "parent.htm"
//-->
</script>


Parent.htm would be the name of your parent page

KlownCoder
03-17-2005, 08:21 PM
I do appreciate the fast reply, but another concern was to be able to go to the parent window and also insert the page the user was trying to access without it into the iframe it was originally supposed to be inside

Mr J
03-18-2005, 12:15 AM
Please try the following example



In the parent page.

<script type="text/javascript" language="javascript">
<!--
loc="page1.htm" // default iframe page
var str = location.search;
if(str != ""){
loc=str.substring(1, str.length)
}

function load_frame(){
document.getElementById('iframe_id').src=loc
}

// add onload="load_frame()" to the opening BODY tag

// -->
</script>

<iframe id="iframe_id" src=""></iframe>

In the page loading into the iframe

<script type="text/javascript" language="javascript">
<!--
if (self == top){
var url = self.location;
top.location.href = "parent_page.htm?" + url;
}
// -->
</script>

KlownCoder
03-18-2005, 01:39 AM
Wow... worked like a charm. Much appreciation. You made it look so easy. I took a totally different approach. Thanks again.



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum