Forum Moderators: mack

Message Too Old, No Replies

Help with iframes please,

         

Joah fr Alberta

6:39 pm on May 9, 2005 (gmt 0)

10+ Year Member



I am building a page with dreamweaver. It has 3 iframes that I have named "topframe" "rightframe" "bottomframe". My question is, by pressing a linked button on my page, is it possible to load up two different images or .htm into more than one iframe? (without having to load up the whole page)
I can only select one "target" using the inspector menu. But I wish for two targets (and some day maybe more). How would I make it load into the target iframe and load another image (simultaneously) into another iframe?

mack

10:13 pm on May 9, 2005 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



Hi Joah fr Alberta, welcome to WebmasterWorld.

I dont have any dreamweaver experience so this will be very general...

Are you using true iframes or a standard framed webpage? Iframes are inline frames and are used to include content within a page. Framed pages are used when you want to display seceral pages within one page.

In either case it is possible to make things happen on other frames by specifying the target frame. The target frame determines where you want the action to occur.

Mack.

Joah fr Alberta

7:14 pm on May 10, 2005 (gmt 0)

10+ Year Member



I'm not exactly sure as to the nature of my markup, I'm just swinging tools and sharpening my art as the old farmers did in feudal Japan.

Perhaps you can have a look at my site <snip> for clarity. The "$499 Spring Special" and "Call 447" are both iframes that I wish to use to display a thumbnail index for project pictures to be available for my clients. When the references button is pressed, it would be nice to change the $499 Spring Special (which will be a fall special at the rate my web page is advancing) ... to change this to "Work Gallery:" as the other center iframe (where the slow house is) changes to another .htm I just don't know how to make two different .htm appear in two different iframes in the one page when one button is pressed. Thanks.

[edited by: mack at 12:42 pm (utc) on May 31, 2005]
[edit reason] No url's please [/edit]

Joah fr Alberta

5:42 am on May 12, 2005 (gmt 0)

10+ Year Member



Anyone?

Joah fr Alberta

5:48 pm on May 12, 2005 (gmt 0)

10+ Year Member



Does anyone know if what I want to do is possible? Do I require to script an .htm file to tell it to load up two target iframes? Can anyone direct me on this one? Thanks.

alex77

6:34 pm on May 12, 2005 (gmt 0)



Hi Joah_fr_Alberta!

What you want to achieve is not directly possible with HTML, you'll need some Javascript to do that. Basically it would look like this:

1. put a script in the <head> section of your page (you already have a <script>-tag there, so you can just add the function).


function chngFrm() {
frames['topframe'].location.href='page1.html';
frames['bottomframe'].location.href='page2.html';
return false;
}

2. now you need to call that script from your link. Put the function call in the onClick method and leave the href empty:

<a href="" onClick="return chngFrm();"

The link won't acutally be processed because of the "return false" in the function.

The downside of that solution is that you have to use Javascript, which maybe not all your viewers' browsers can use.

How about changing the site concept a bit instead? You could put the items you have in iframes in a table-based layout, and then just make a second page that will be called when someone clicks the link, with the items you want to be shown then. That would avoid the Javascript.

Alex

Joah fr Alberta

4:52 pm on May 18, 2005 (gmt 0)

10+ Year Member



I will get on this right away. I thought a script would be necessary for what I wanted to achieve. I considered creating a link to another page but then I want to avoid having my web site refresh at every click. Besides I'm betting most of my clients will be using IE :( and they will probably have the java plug-in. Anyhow, this is a long shot but I don't suppose this is the same Alex that helped me at the Remedy a couple weeks back? Yeah, and this big round rock is only occupied by the ten of us, sheesh. Anyhow, I thank you sir for your reply on this matter.

Yeah, it works beautifully in IE but no so good in Safari :(

Q. How would I create several different funtions, so that if I click on one link it will change two frames and if I click on the other link it will change other forms? Do I assign a value to the chngFrm? or ...

Okay, stumped again. So close. Can I expect the same response from within the iframe? That is, when I selected a link from within my index.htm it will open a second .htm within the toptable. Can I click a button within this second .htm to change two frames within the index.htm?

Do I need to assign a relative path?
I like to reference myself at times to the physical things in our nature, I've always been this way. And it's funny how yesterday I tried everything and finally collapsed at the foot of my wall. Yet today my fingers execute a few dextrous strokes and everything works just the way I planned. I like to believe that I am within a bearing spinning symmetrical to my surroundings and that I must wait for my surroundings at times to catch up with me (or me with them) so that my surroundings and I may spin as a whole rather than just sit spinning in my bearing.
"Every man imposes upon himself a resistance for survival, and it is in the end that his efforts shall make him." -- Joah

[edited by: mack at 10:29 am (utc) on May 31, 2005]
[edit reason] Merged posts [/edit]

alex77

8:32 pm on May 18, 2005 (gmt 0)



Hi Joah_fr_Alberta,

no, sorry, I must be another Alex. But well, you never know till you ask :)

Okay, to your scripts:

On the main page, I'd change the function somewhat:

Instead of creating a new function for each frame change you want to make, you can assign parameters:


function cngFrm(top, right) {
frames['topframe'].location.href = top;
frames['rightframe'].location.href = right;
return false;
}

Thus, you'll need only one function, which you can call respectively:


<a href="" onClick="return cngFrm('about.htm', 'about header.htm')">

same for the other links, with different parameters. Saves some code and you'll know what's opening when you look at the link code.

With the change from one of the frames, you're actually on the right track already:


function residentialFrm() {
parent.frames['/index.html/topframe'].location.href='residential commercial.htm';
parent.frames['rightframe'].location.href='residential header.htm';
return false;
}

parent.frames calls the frames collection on the parent window, that would be the main page. You should just replace

frames['/index.html/topframe']
with
frames['topframe']
, you can't have a relative reference there, just the frame name. The relation is done by the parent keyword already.

I can't try it in Safari because I don't have a Mac around, but in theory it should be working there, too. Javascript is enabled?

Internet Explorer is the most common browser still, true, but Mozilla-based ones are catching up. You might want to try it also in Firefox, for example. Your page works fine there, though.

okay, I hope I could help you along. Have a nice day, and don't let your page get down on you so much, after all, it's just html :D

Alex

Lynque

3:18 am on May 20, 2005 (gmt 0)

10+ Year Member



Not sure that this applies but if you have three frames could you not just have a frameset and use the DOM to target frames you wanted to load the pages in (onEvent)?

You can target as many frames (or elements as you like) as long as it is event driven.

You can control any element from any element when using the DOM

alex77

8:52 pm on May 20, 2005 (gmt 0)



It would be a bit difficult to do the layout in a frameset, the design relies quite heavily on the position of the iframes. Yet, I don't really get what you mean by using DOM. Could you elaborate that some more?

Lynque

2:37 pm on May 24, 2005 (gmt 0)

10+ Year Member



Joah fr Alberta,

If you were to look into using a frameset instead of the Iframe you could use the DOM (document Object Model) to control what is loaded in the two frames, in fact you could check to see what is loaded in frame 1 and load frame 2 based on frame 1's content.

The trouble with Iframes is that they have no parent, when using a frameset you can target elements within...

parent.main.location.href("page to load")

Frameset's are very useful for this type of thing.

Good luck

alex77

8:24 pm on May 26, 2005 (gmt 0)



IFrames are part of the frames collection, just like "normal" frames, so there shouldn't be a problem calling
parent.frames[<name of targetframe>].location.href
from an IFrame.

Lynque

8:50 pm on May 26, 2005 (gmt 0)

10+ Year Member



I didn't know that Alex, (never tried it though)
I assumed that because the iFrame is independent and not part of any other element that it had no parent.

Cheers