Wrox Programmer Forums
Go Back   Wrox Programmer Forums > Web Programming > JavaScript > Javascript How-To
|
Javascript How-To Ask your "How do I do this with Javascript?" questions here.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the Javascript How-To section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 7th, 2004, 11:06 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default Determine if Parent Document Exists

I have a page that contains an IFRAME. There is a possibility that a search engine will direct a visitor directly to the page contained in the IFRAME, and so within that page I would like to include some Javascript that can determine if the parent page is present or has a specific URL, and then either display a message with a link to the parent page, or automatically redirect them to the home page.

I need help How-to determine if the parent exists or has a specific URL, and how to redirect them to a specific URL (if that is possible)

Thanks in advance

Mike
EchoVue.com
__________________
Mike
EchoVue.com
 
Old December 7th, 2004, 11:26 PM
Friend of Wrox
 
Join Date: Nov 2003
Posts: 1,285
Thanks: 0
Thanked 2 Times in 2 Posts
Default

In the code of your iFrame add this JavaScript:

if(!window.parent||parent.location != "YOUR PARENT URL")
window.location = "YOUR PARENT URL";

hth

-Snib - http://www.snibworks.com
Where will you be in 100 years?
 
Old December 7th, 2004, 11:36 PM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Fantastic! That worked great. Thanks a million.

Mike
EchoVue.com
 
Old December 8th, 2004, 12:31 AM
Friend of Wrox
 
Join Date: Oct 2004
Posts: 564
Thanks: 0
Thanked 4 Times in 4 Posts
Default

Well, it worked great until I uploaded it to my site. It started an eternal loop, continually loading the parent into the IFRAME.

This is an edited reply with how I fixed it. I used alerts() to determine what the location of the parent was and realized that the parent required a / on the end of it.

It works great now.

Mike
EchoVue.com





Similar Threads
Thread Thread Starter Forum Replies Last Post
document() - check if a file exists N.Todd XSLT 2 September 19th, 2007 05:50 AM
Determine If A Tag or Node Exists coolpeep Classic ASP XML 2 July 20th, 2006 06:16 PM
Determine if numeric Scootterp Access VBA 4 March 2nd, 2006 08:44 AM
howto test document exists folklayer XSLT 2 October 19th, 2005 05:56 PM
Determine OS adman Beginning VB 6 2 January 5th, 2004 02:26 AM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.