Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-22-2004, 11:10 PM   PM User | #1
tpeck
Regular Coder

 
tpeck's Avatar
 
Join Date: Oct 2002
Location: Sydney, Australia
Posts: 771
Thanks: 40
Thanked 5 Times in 4 Posts
tpeck is on a distinguished road
How to link to an anchor in another frameset

Hi. I want to make a link in a header frame of a two-frame frameset that loads a new two-frame frameset, but also goes to an anchor within the new main frame.

So the link would load the new page with a header and the main frame, but display the part of the main frame where the anchor is.

At present, I can load the new page, <a href="feedback.htm"> where feedback.htm is a two page frameset, consisting of topfeed.htm and mainfeed.htm,

but I suspect that javascript is the only way to also go to an anchor in the mainfeed.htm frame.

Of course, <a href="feedback.htm#feedback">won't find the anchor in mainfeed.htm.

What should I try?

Thank you everybody,

Terry
tpeck is offline   Reply With Quote
Old 12-23-2004, 01:30 AM   PM User | #2
sage45
Super Moderator


 
Join Date: May 2002
Posts: 1,036
Thanks: 0
Thanked 11 Times in 11 Posts
sage45 is an unknown quantity at this point
I posted on this once before:

http://www.codingforums.com/showthread.php?t=7677

The only way I have found that this type of thing will work is by using a little bit of Javascript... (this thing just about killed me two years ago when I racked my brain in figureing it all out)... The reason why it will not work from a standard link is because a standard link is erased once the browser loads the frameset index, in this case bobsframeset.htm... bobsframeset does not hold the anchor, instead bobsframeset holds the pages that will appear within the frameset, bobsbottom (this one is where the anchor resides) and bobstop... So what you have to do is use javascript to create the frameset page and plug in the link information (target page and target anchor) after the frameset loads...

Basically your link would look like:

Code:
Test this <A HREF="bobsframeset2.htm?newLink=bobsbottom.htm&newAnchor=two">two</A>
and your bobsframeset2.htm page would look like such:
Code:
<HTML>
<HEAD>
</HEAD>
<SCRIPT LANGUAGE="JavaScript">
function getParams() {
var idx = document.URL.indexOf('?');
var params = new Array();
if (idx != -1) {
var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
for (var i=0; i<pairs.length; i++) {
nameVal = pairs[i].split('=');
params[nameVal[0]] = nameVal[1];
   }
}
return params;
}
params = getParams();
</SCRIPT>
</HEAD>
<SCRIPT LANGUAGE="JavaScript">
newLink = unescape(params["newLink"]);
newAnchor = unescape(params["newAnchor"]);

document.write("<FRAMESET ROWS=14%,* FRAMEBORDER=NO FRAMESPACING=0>");
document.write("<FRAME SCROLLING=NO NORESIZE FRAMEBORDER=NO SRC=bobstop.htm NAME=top>");
document.write("<FRAME SCROLLING=AUTO FRAMEBORDER=NO SRC=" + newLink + "#" + newAnchor + " NAME=main>");
document.write("</FRAMESET>");
</SCRIPT>
<NOFRAMES>
<BODY BGCOLOR="#000000" TEXT="#000000" LINK="#000000" VLINK="#000000" ALINK="#000000">
</BODY>
</NOFRAMES>
</HTML>
So what you are doing is using javascript to build the frameset and use the search string to fill in the link/anchor information as the frameset is built so that the referenced page opens to that anchor...

HTH,

-sage-
__________________
HTML & CSS Forum Moderator

"If you don't know what you think you know, then what do you know."
R.I.P. Derrick Thomas #58
1/1/1967 - 2/8/2000
sage45 is offline   Reply With Quote
Old 12-23-2004, 01:35 AM   PM User | #3
gaBRiel
New Coder

 
Join Date: Sep 2004
Location: Brazil
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
gaBRiel is an unknown quantity at this point
you probably have this:
//feedback.htm
<frameset rows="...">
<frame src="topfeed.htm">
<frame src="mainfeed.htm">
</frameset>

it DOES work if you do this:
<frameset rows="...">
<frame src="topfeed.html">
<frame src="mainfeed.htm#feedback">
</frameset>

when it loads, it will automaticaly go to your anchor thing hopefully...
gaBRiel is offline   Reply With Quote
Old 12-23-2004, 01:38 AM   PM User | #4
sage45
Super Moderator


 
Join Date: May 2002
Posts: 1,036
Thanks: 0
Thanked 11 Times in 11 Posts
sage45 is an unknown quantity at this point
This is the only problem with your solution. What if someone comes to this frame but not from the link, then they would be directed to the anchor and not the top of file...

-sage-
__________________
HTML & CSS Forum Moderator

"If you don't know what you think you know, then what do you know."
R.I.P. Derrick Thomas #58
1/1/1967 - 2/8/2000
sage45 is offline   Reply With Quote
Old 07-29-2005, 01:08 PM   PM User | #5
gtgart
New to the CF scene

 
Join Date: Jul 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
gtgart is an unknown quantity at this point
Thanks, I will give this a try it looks like it will work.

Thanks

Quote:
Originally Posted by sage45
I posted on this once before:

http://www.codingforums.com/showthread.php?t=7677

The only way I have found that this type of thing will work is by using a little bit of Javascript... (this thing just about killed me two years ago when I racked my brain in figureing it all out)... The reason why it will not work from a standard link is because a standard link is erased once the browser loads the frameset index, in this case bobsframeset.htm... bobsframeset does not hold the anchor, instead bobsframeset holds the pages that will appear within the frameset, bobsbottom (this one is where the anchor resides) and bobstop... So what you have to do is use javascript to create the frameset page and plug in the link information (target page and target anchor) after the frameset loads...

Basically your link would look like:

Code:
Test this <A HREF="bobsframeset2.htm?newLink=bobsbottom.htm&newAnchor=two">two</A>
and your bobsframeset2.htm page would look like such:
Code:
<HTML>
<HEAD>
</HEAD>
<SCRIPT LANGUAGE="JavaScript">
function getParams() {
var idx = document.URL.indexOf('?');
var params = new Array();
if (idx != -1) {
var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
for (var i=0; i<pairs.length; i++) {
nameVal = pairs[i].split('=');
params[nameVal[0]] = nameVal[1];
   }
}
return params;
}
params = getParams();
</SCRIPT>
</HEAD>
<SCRIPT LANGUAGE="JavaScript">
newLink = unescape(params["newLink"]);
newAnchor = unescape(params["newAnchor"]);

document.write("<FRAMESET ROWS=14%,* FRAMEBORDER=NO FRAMESPACING=0>");
document.write("<FRAME SCROLLING=NO NORESIZE FRAMEBORDER=NO SRC=bobstop.htm NAME=top>");
document.write("<FRAME SCROLLING=AUTO FRAMEBORDER=NO SRC=" + newLink + "#" + newAnchor + " NAME=main>");
document.write("</FRAMESET>");
</SCRIPT>
<NOFRAMES>
<BODY BGCOLOR="#000000" TEXT="#000000" LINK="#000000" VLINK="#000000" ALINK="#000000">
</BODY>
</NOFRAMES>
</HTML>
So what you are doing is using javascript to build the frameset and use the search string to fill in the link/anchor information as the frameset is built so that the referenced page opens to that anchor...

HTH,

-sage-
gtgart is offline   Reply With Quote
Old 08-01-2005, 09:58 AM   PM User | #6
gtgart
New to the CF scene

 
Join Date: Jul 2005
Posts: 6
Thanks: 0
Thanked 0 Times in 0 Posts
gtgart is an unknown quantity at this point
Hi Sage,

thanks, can you show me an example of this working?

I have tried it and cannot get it working.


Thanks,

Greg.

Quote:
Originally Posted by sage45
I posted on this once before:

http://www.codingforums.com/showthread.php?t=7677

The only way I have found that this type of thing will work is by using a little bit of Javascript... (this thing just about killed me two years ago when I racked my brain in figureing it all out)... The reason why it will not work from a standard link is because a standard link is erased once the browser loads the frameset index, in this case bobsframeset.htm... bobsframeset does not hold the anchor, instead bobsframeset holds the pages that will appear within the frameset, bobsbottom (this one is where the anchor resides) and bobstop... So what you have to do is use javascript to create the frameset page and plug in the link information (target page and target anchor) after the frameset loads...

Basically your link would look like:

Code:
Test this <A HREF="bobsframeset2.htm?newLink=bobsbottom.htm&newAnchor=two">two</A>
and your bobsframeset2.htm page would look like such:
Code:
<HTML>
<HEAD>
</HEAD>
<SCRIPT LANGUAGE="JavaScript">
function getParams() {
var idx = document.URL.indexOf('?');
var params = new Array();
if (idx != -1) {
var pairs = document.URL.substring(idx+1, document.URL.length).split('&');
for (var i=0; i<pairs.length; i++) {
nameVal = pairs[i].split('=');
params[nameVal[0]] = nameVal[1];
   }
}
return params;
}
params = getParams();
</SCRIPT>
</HEAD>
<SCRIPT LANGUAGE="JavaScript">
newLink = unescape(params["newLink"]);
newAnchor = unescape(params["newAnchor"]);

document.write("<FRAMESET ROWS=14%,* FRAMEBORDER=NO FRAMESPACING=0>");
document.write("<FRAME SCROLLING=NO NORESIZE FRAMEBORDER=NO SRC=bobstop.htm NAME=top>");
document.write("<FRAME SCROLLING=AUTO FRAMEBORDER=NO SRC=" + newLink + "#" + newAnchor + " NAME=main>");
document.write("</FRAMESET>");
</SCRIPT>
<NOFRAMES>
<BODY BGCOLOR="#000000" TEXT="#000000" LINK="#000000" VLINK="#000000" ALINK="#000000">
</BODY>
</NOFRAMES>
</HTML>
So what you are doing is using javascript to build the frameset and use the search string to fill in the link/anchor information as the frameset is built so that the referenced page opens to that anchor...

HTH,

-sage-
gtgart is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:10 PM.


Advertisement
Log in to turn off these ads.