Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    Regular Coder tpeck's Avatar
    Join Date
    Oct 2002
    Location
    Sydney, Australia
    Posts
    821
    Thanks
    44
    Thanked 6 Times in 5 Posts

    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

  • #2
    Super Moderator sage45's Avatar
    Join Date
    May 2002
    Posts
    1,060
    Thanks
    0
    Thanked 13 Times in 13 Posts
    I posted on this once before:

    linking to an anchor inside a frameset

    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

  • #3
    New Coder
    Join Date
    Sep 2004
    Location
    Brazil
    Posts
    25
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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...

  • #4
    Super Moderator sage45's Avatar
    Join Date
    May 2002
    Posts
    1,060
    Thanks
    0
    Thanked 13 Times in 13 Posts
    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

  • #5
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    linking to an anchor inside a frameset

    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-

  • #6
    New to the CF scene
    Join Date
    Jul 2005
    Posts
    6
    Thanks
    0
    Thanked 0 Times in 0 Posts
    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:

    linking to an anchor inside a frameset

    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-


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •