Forum Moderators: open

Message Too Old, No Replies

force child page to load in iframe on parent

need help with iframes

         

bubba4gman

10:27 pm on Jun 14, 2005 (gmt 0)

10+ Year Member



Ok, I need some help with adding to the little piece of code shown in the quote below.
I have some pages that load in a pop-up window. I need to be able to differentiate whether the user accessed the pop-up content from my website, or from another location (search enginge). I need it to redirect to the main page only if they accessed the content from outside the website.

Thanks,

GMan


I have a website with multiple pages that load in an iframe on the main page, but I don't want users to be able to access the pages without them being in the iframe of the main page and basically I want to force the pages to open in the main page if it is access directly

right now on each page I have this code:

<script type="text/javascript">
if(top.location == self.location)
{
top.location.href = 'my main page'
}
</script>

this works to get them to the main page, but I want the page the user directly accessed to be open in the main

any help would be greatly appreciated

Thanks,
ryanc

Dijkgraaf

1:04 am on Jun 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well for starters you will want to pass the page to load to the main page
e.g. top.location.href = 'my main page?page=this page'

Then in your main page, you want to access the query string and parse out the page name.

And then set the location of the frame to that page.

bubba4gman

1:31 am on Jun 15, 2005 (gmt 0)

10+ Year Member



I'm a little confused by that. All I want to do is determine if they accessed the content that belongs to a pop-up window by clicking for it from my website, or if they accessed that content from a search enginge. If they accessed it from the website, then they are seeing it in a pop-up window and nothing needs to happen. If they accessed it from a search enging, they are in a regular window and that window needs to bypass the content and redirect to the main page of the website. I already used that script for my iframe pages to redirect, now I need to modify it to use in case they are accessing my pop-up content from a search engine.

Dijkgraaf

3:07 am on Jun 15, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Well how will your main page know which page they requested?
It won't unless you pass it as a paramater to the main page.

Then you want your main page to check if that parameter is set, and if so you want your main page to set the location of that frame to the page they originally arrived at.

bubba4gman

9:58 pm on Jun 15, 2005 (gmt 0)

10+ Year Member



well, I really don't care which page they requested. The popup content consists of things like extra info on using a credit card, or how to shop through the website. Apart from the site (not having the site showing behind it), it doesn't mean much. So, if they got to the pop-up content from a search engine, I want to send them to the main page of the site. If they are accessing the popup content from the website, then it loads in a small window of a specified size. I just want to detect where they are coming from and direct them to the main page if they are not coming from the page that the pop-up belongs to.

Dijkgraaf

4:18 am on Jun 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Then check the window.opener attribute before doing the redirect. If the window was opened via JavaScript then this would be set, otherwise it should be null.

bubba4gman

9:26 pm on Jun 16, 2005 (gmt 0)

10+ Year Member



how is that done. I'm prettye clueless at javascript stuff, other than to cut, paste, amd modify stuff that already works.

Thanks!

Dijkgraaf

10:23 pm on Jun 16, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Like this

<script type="text/javascript">
if ((top.location == self.location) &&!(window.opener))
{
top.location.href = 'my main page'
}
</script>

In fact you could probably get rid of checking top.location == self.location althogether for your popup pages, as that condition would always be true for them.

bubba4gman

1:46 am on Jun 17, 2005 (gmt 0)

10+ Year Member



You rock dude!

That's exactly what I wanted.
Thanks!