Using javascript to tell a frame which page to load

F

Fokke Nauta

Hi all,

I have a menu wich has 10 links, all to the same frameset but each link
needs to load the frameset with a different page in one of the frames. I
could achieve this with creating 10 separate framesets, each loading a
different page in one of the frames. I think there should be a more advanced
way, with using only one frameset but using javascript to tell the frame
which page to load in one of the frames when the link is clicked.
I can't write this script. Is there anyone out here who can help me with
this?
Many thanks in advance.

With kind regards,
Fokke Nauta
 
R

rf

Fokke Nauta said:
Hi all,

I have a menu wich has 10 links, all to the same frameset but each link
needs to load the frameset with a different page in one of the frames. I
could achieve this with creating 10 separate framesets, each loading a
different page in one of the frames. I think there should be a more
advanced way, with using only one frameset but using javascript to tell
the frame which page to load in one of the frames when the link is
clicked.
I can't write this script. Is there anyone out here who can help me with
this?

Not a javascript problem. Look into the target attribute?

Also, google for "frames are evil"
 
F

Fokke Nauta

rf said:
Not a javascript problem. Look into the target attribute?

Also, google for "frames are evil"

It's not a problem, it's a question.
And I would prefer this point with I-frames, as I use I-frames on this site.
I have simplified this question with the use of frames.
And please re-read my query.

Rgs,
Fokke Nauta
 
R

rf

Fokke Nauta said:
It's not a problem, it's a question.

Problem/question. Whatever.
And I would prefer this point with I-frames, as I use I-frames on this
site.

And this is the very first time you have mentioned iframes (note the lack of
a - in the elements name).
I have simplified this question with the use of frames.

No you have not simplifed the question. You have turned the question into a
different one. Not that it matters in this instance.
And please re-read my query.

For an answer to your original question and also to your new question please
re-read my reply.

I'll even expand on it.

The target attribute of the a element is used to specify which frame (or
iframe) the paged mentioned in the href attribute is loaded.

You don't need any javascript. It's all done with straight vanilla HTML and
is one of the very fundamental things that frames (and iframes) were
designed for. Have a look at the HTML manual for any further information.
 
F

Fokke Nauta

rf said:
Problem/question. Whatever.


And this is the very first time you have mentioned iframes (note the lack
of a - in the elements name).

Basically it dosn't make a difference.
No you have not simplifed the question. You have turned the question into
a different one. Not that it matters in this instance.


For an answer to your original question and also to your new question
please re-read my reply.

I'll even expand on it.

The target attribute of the a element is used to specify which frame (or
iframe) the paged mentioned in the href attribute is loaded.

Yes, but to specify which frame a page is loaded is not the question at all.
Perhaps I did not make myself clear. I am not talking about frames, but
about to specify which page is loaded in a certain frame. I have specified
the frame in which I want to load a page. The point is, that I want to
specify which page is loading into that frame.
You don't need any javascript. It's all done with straight vanilla HTML
and is one of the very fundamental things that frames (and iframes) were
designed for. Have a look at the HTML manual for any further information.

You definitely need javascrip for this.
 
F

Fokke Nauta

Hi Fokke,

I'm just learning a bit of javascript myself. The book I have gives an
example of what I think you want.

Have a look here:

http://www.javascriptworld.com/

and look at the Book Resources. The scripts are downloadable. In
particular, take a look at Chapter 5: Setting a target.

http://www.javascriptworld.com/chap05/frameset4.html

Hi Richard,

Thanks for your response.
A very nice site you mentioned. Very interesting, I will look further into
that.
But it's not about setting a target. I have specified the target frame, but
want to specify which page to load.

Best regards,
Fokke
 
D

Dr J R Stockton

In comp.lang.javascript message said:
It's not a problem, it's a question.
And I would prefer this point with I-frames, as I use I-frames on this site.
I have simplified this question with the use of frames.
And please re-read my query.

Page <URL:http://www.merlyn.demon.co.uk/linxchek.htm>, as a local copy
with its include files, will load an iframe with HTML or TXT files at a
great rate, especially in Chrome. Search its source for 'ReadWebPage',
and read nearby, to see how; and search also for 'Fram'.
 
R

rf

Yes, but to specify which frame a page is loaded is not the question at
all.
Perhaps I did not make myself clear. I am not talking about frames, but
about to specify which page is loaded in a certain frame. I have specified
the frame in which I want to load a page. The point is, that I want to
specify which page is loading into that frame.

Perhaps you didn't. I had to read the original question a number of times
before I noticed what you are really asking. Let me rephrase it:

You have a page with ten links on *to another page* and that other page has
an iframe on it. You want each of the links to cause a different page to be
loaded into that iframe on that other page. Correct?

Well, that is one of the evils of frames and iframes. You cannot link to
them.
You definitely need javascrip for this.

Not if you do not use iframes in the first place. And not if you do your
processing server side, where this sort of stuff should be done.
 
F

Fokke Nauta

rf said:
Perhaps you didn't. I had to read the original question a number of times
before I noticed what you are really asking.

Sorry! I aploogize for that.
Perhaps a language problem?

Let me rephrase it:
You have a page with ten links on *to another page* and that other page
has an iframe on it. You want each of the links to cause a different page
to be loaded into that iframe on that other page. Correct?

Yes, correct.
Well, that is one of the evils of frames and iframes. You cannot link to
them.


Not if you do not use iframes in the first place. And not if you do your
processing server side, where this sort of stuff should be done.

I still have a javascript which did this for a frameset. Somehow if you link
to this frameset like frameset.htm?first, it would load the frameset with
the page first.htm in one of the frames. I tried to convert this script to
use it with my current situation, bit it did not work.

I have a hobby-site, I'm not a professional. I am not familiar with
server-side scripting.

Rgs,
Fokke
 
B

beegee

I still have a javascript which did this for a frameset. Somehow if you link
to this frameset like frameset.htm?first, it would load the frameset with
the page first.htm in one of the frames. I tried to convert this script to
use it with my current situation, bit it did not work.


Well this is sort of interesting. If the URL was frameset.htm#first
that would be an anchor. You could pick the anchor up in javascript
on the framset page with something like:

var anchor = self.document.location.hash

Then you could do something like:

var fileToLoad;
switch(anchor)
{
case "first": fileToLoad = "first.htm"; break;
case "second": etc.
}

var frameElem = docment.getElementById("myFrame");
frameElem.src = fileToLoad;


Not sure of your level of programming so "etc." is not real
javascript. Again, this is easier done with server side programming
as others have pointed out. Also, it's better done not using iframes
at all.

Bob
 
F

Fokke Nauta

beegee said:
Well this is sort of interesting. If the URL was frameset.htm#first
that would be an anchor. You could pick the anchor up in javascript
on the framset page with something like:

var anchor = self.document.location.hash

Then you could do something like:

var fileToLoad;
switch(anchor)
{
case "first": fileToLoad = "first.htm"; break;
case "second": etc.
}

var frameElem = docment.getElementById("myFrame");
frameElem.src = fileToLoad;


Not sure of your level of programming so "etc." is not real
javascript. Again, this is easier done with server side programming
as others have pointed out. Also, it's better done not using iframes
at all.

Bob

Hi Bob,

Thanks. I will put the code I used with frames underneath this post.
I have some programming experience in Basic and 4DOS batch commands and in
Unix shell scripting. But I'm not deep into javascripts.
I have no experience with server side programming. Is that .ASP pages?
And what's wrong with I-frames?

Rgs,
Fokke

---------------------------------------------------------
<script>

ref = location.href;

pageRE = /(\?|\&)page=(\w|,)*/;
pageStr = ref.match(pageRE);

page = "main";

if(pageStr != null) {
// remove the (? or &)page= part of the string
page = pageStr[0].substring(6, pageStr[0].length);

// change all comma's back to slashes
page.replace("/,/", "/\//");
}

document.write("<frameset framespacing=\"0\" border=\"false\"
frameborder=\"0\" rows=\"125,*\">");
document.write("<frame name=\"banner\" src=\"banner.htm\" scrolling=\"no\"
document.write( said:
document.write("<FRAME NAME=\"main\" SRC=\"" +page + ".htm\"
scrolling=\"auto\" >");
document.write("</frameset><noframes><body><p>This page uses frames, but
your browser doesn't support
them.</p></body></noframes></frameset></html>");

</script>
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,770
Messages
2,569,583
Members
45,073
Latest member
DarinCeden

Latest Threads

Top