...

View Full Version : How to link to an anchor in another frameset



tpeck
12-22-2004, 11:10 PM
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

sage45
12-23-2004, 01:30 AM
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:


Test this <A HREF="bobsframeset2.htm?newLink=bobsbottom.htm&newAnchor=two">two</A>and your bobsframeset2.htm page would look like such:
<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-

gaBRiel
12-23-2004, 01:35 AM
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... :o

sage45
12-23-2004, 01:38 AM
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-

gtgart
07-29-2005, 01:08 PM
Thanks, I will give this a try it looks like it will work.

Thanks :)


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:


Test this <A HREF="bobsframeset2.htm?newLink=bobsbottom.htm&newAnchor=two">two</A>and your bobsframeset2.htm page would look like such:
<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
08-01-2005, 09:58 AM
Hi Sage,

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

I have tried it and cannot get it working.


Thanks,

Greg.


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:


Test this <A HREF="bobsframeset2.htm?newLink=bobsbottom.htm&newAnchor=two">two</A>and your bobsframeset2.htm page would look like such:
<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-
:cool:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum