Forum Moderators: open

Message Too Old, No Replies

help with loading iframe content

         

johnace

2:51 pm on Mar 29, 2005 (gmt 0)

10+ Year Member



Can anyone help with how to load iframe content without using the "src" attribute.

Ideally I'd like to do this with a 'body onload' command or something like that but am thick as two short planks when it comes to JS, still getting to grips with CSS and HTML I'm afraid!

The problem with "src" is that whilst it loads in the chosen page well enough, it's impossible to direct someone to a certain section of the site (via a link in an e-mail for example) without having the page named after the "src" attribute load up instead.

I have absolutely no doubt this question shows what a novice I am but all help appreciated!

tedster

7:32 pm on Mar 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Welcome to the forums, johnace.

You are correct that this will require javascript. So you will need your thinking cap for a bit, but this is not the most complex javascript by a largemeasure - it's well with the grasp of us mere mortals (trust me, I'm no js master, either.)

Any html document that is displayed within a frame or an iframe can (and should, IMO) also contain script that inserts it into its parent page in the event that someone comes there directly -- an "orphan"display of a page that is intended to have a "parent." Search engines index frame documents a lot and send people directly to the orphan all the time - and with such a script installed, you can justr giver someone the url of the iframed page and the script will take care of inserting it into its parent page.

We have an example of how to do this with a regular frame page - but you can adapt the idea for an iframe page with just a few changes:

See Message #21 on:
[webmasterworld.com...]

Also note that another member, visuale, is working on the same issue right now.
[webmasterworld.com...]

johnace

10:35 pm on Mar 29, 2005 (gmt 0)

10+ Year Member



Thanks for the reply and the welcome.

I think I might need leading by the hand on this! I've attemped to run the code that Visuale posted but all I get is the main index page inside the iframe.

I understand the idea of what's going on with the 'master.html' page but I don't understand the code enough to spot any mistakes I'm making.

tedster

11:55 pm on Mar 29, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Start with the link I gave you (that's where visuale started)

Message #21 on:
[webmasterworld.com...]

There is a lot of explanation there about what the scripts are doing. Yes, I realize this may be a bit of a stretch for you...but you have expressed a sophisticated need and that takes a bit of a sophisticated solution.

That's how we all grow our skills, I think - and there is definitely help available here on the forums. We won't just do the work for you, but we'll be glad to help you through some sticky spots.

chriswragg

2:44 pm on Mar 30, 2005 (gmt 0)

10+ Year Member



Hello

Here we go...

<script language="javascript">
if (top.location.href == document.location.href)
{
top.location.href = 'PageWithiframe.htm' ;
}
else
{
}
</script>

This script first checks to see if the page the code is on, is the same as the file name in the address bar.

If the is true, it means that your page isn't being viewed in the iframe, and so sends the user to "PageWithiframe.htm". In the code you should replace this with the name of the page with the iframe (eg index.htm). If the statement is false, it does nothing.

Hope this helps,

Chris

P.S. This means you can link to the iframe page in the email, and then it will redirect the user

tedster

9:58 pm on Mar 30, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That works nicely if there are only a few possibly orphaned pages - but it does require a separate "PageWithiframe.htm" for each possible orphan.

The more involved script will work with an unlimited number of orphaned pages and still require just one "page with iframe" master page.

chriswragg

3:57 pm on Mar 31, 2005 (gmt 0)

10+ Year Member



Surely having one master page would require server side scripting to determine to location of the page in the iframe. This could be in the form of PageWithiframe.php?iframesrc=page1.htm

Is this what you mean tedster/johnace?

Chris

tedster

4:17 pm on Mar 31, 2005 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



That is the idea, but it can all be done with client-side javascript - see the reference I made earlier, a solution for regular frameset pages.

Message #21 on:
[webmasterworld.com...]