Forum Moderators: open

Message Too Old, No Replies

linking from another site into an iframe page on my site

iframe link

         

scott859

4:22 am on Apr 2, 2005 (gmt 0)

10+ Year Member



Greetings,

I'm trying to ensure that someone linking to an iframe page outside of my site - goes directly to the iframe page inside the parent page. This was discussed on this post: [webmasterworld.com...]

I have somewhat limited JavaScript knowledge, so forgive me if this seems really basic.

Here's my parent (test)page: http://www.example.com/welcome2.htm There are 2 iframes on the page - the one on the left is navigation an the one on the right is named "main" - this is where i want the child pages to appear. I haven't set a source for the "main" iframe, thinking the script will write the source.

Here is a sample page I am trying to load into the "main" iframe: http://www.example.com/iframes/welcome2-main-iframe.htm

I'm trying ensure the content pages open up in the frame labled "main" when linked to from outside of my site.

For some reason(s) it isn't working. The child page passes its URL to the parent - but the parent doesn't put it in the "main" iframe.

I'm putting this code into the <head> tags of the child pages:

<script language="JavaScript" type="text/javascript">

passpage = document.URL
if (top.location == self.location)
top.location.href="http://www.example.com/welcome2.htm?" + passpage

</script>

On the parent page I've placed this code:

<script language="JavaScript" type="text/javascript">

origURL = parent.document.URL
contentURL = origURL.substring(origURL.indexOf('?')+1, origURL.length)

document.write('<frame src=\"' + contentURL + '\" name="main"><\/iframe>')

</script>

I have the parent page JS just inside the <body> tag, not sure if this is correct.

Any suggestions would be appreciated.

Thanks.

<Changed personal URLs
to example.com
See Terms of Service [webmasterworld.com]>

[edited by: tedster at 7:39 am (utc) on April 2, 2005]

scott859

5:23 am on Apr 2, 2005 (gmt 0)

10+ Year Member



Just wanted to say I found what I was doing wrong - the script is working now.... finally.

Thanks for looking at this.

tedster

7:41 am on Apr 2, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Glad you got it working, Scott. Would you share what was tripping you up? Lots of people seem to struggle with this script at first, and knowing what the common stumbling blocks are could help a lot of people.

Thanks