如何在 HTML 中打开指向另一个框架的链接?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/40565672/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-29 14:01:53  来源:igfitidea点击:

How to open a Link to another Frame in HTML?

htmlanchorhrefframetarget

提问by J patel

UPDATE: It is still Not working. The Links are clickable but they are not taking where its suppose too. Example, From Frame 1 when You click on the Contact information, it should open that in Frame 3. From Fame 1, when you click on Hours of Operation, it should display the Hours of Operation in Frame 3.

更新:它仍然无法正常工作。链接是可点击的,但它们也没有采用它的假设。例如,从第 1 帧开始,当您单击联系信息时,它应该在第 3 帧中打开该信息。从 Fame 1 开始,当您单击营业时间时,它应该在第 3 帧中显示营业时间。

UPDATE 2: After adding # sign...When I click on the Contact Information..It would display THE FRAME 1 in FRAME 3 and get Rid of what I had in FRAME 3. Which is not I am Suppose to Do.

更新 2:添加 # 符号后...当我点击联系信息时..它会在 FRAME 3 中显示 FRAME 1 并摆脱我在 FRAME 3 中的内容。这不是我应该做的。

So..I have four Frames. The code for those frames is displayed below. So It will display four Different frames in one page. The Picture of that is also displayed. enter image description here

所以..我有四个框架。这些框架的代码如下所示。所以它将在一页中显示四个不同的框架。也显示了那个图片。在此处输入图片说明

<!DOCTYPE html>
<html>

    <head> 
        <title> A4 - HTML Frames - Jainamkumar Patel </title>
    </head>

    <frameset cols = "20%,50%">
        <frame src = "frame1.html">

    <frameset rows = "30%,30%">
        <frame src = "frame2.html">

    <frameset cols = "25%,25%">
        <frame src = "frame3.html" name = "frame1">
        <frame src = " ">

        </frameset>
    </frameset>
 </frameset>

</html>

Now This is what I want to Do:

现在这就是我想要做的:

Pane 2 contains hyperlinks to contact information, services, hours of operation, product descriptions. There are to be at least 3 links to the product descriptions.
Pane 3 of the browser window holds the pages describing contact information, services, hours of operation, to which appropriate links refer.

窗格 2 包含指向联系信息、服务、营业时间、产品说明的超链接。至少有 3 个链接到产品说明。
浏览器窗口的窗格 3 包含描述联系信息、服务、营业时间以及相应链接所指的页面。

Frame 1 Code:

第一帧代码:

<!DOCTYPE html>
<html>

    <head> 
        <link rel = "stylesheet" href =  "HTML_Style_Sheets.css">
    </head>

    <body> 

        <h1> CRC Software Solutions </h1>
        <h2> About Us </h2>

        <p><a href = "#frame3.html" target = "frame1"> Contact Information </a></p>
        <p><a href = "#frame3.html" target = "frame1"> Services </a></p>
        <p><a href = "#frame3.html" target = "frame1"> Hours of Operation </a></p>
        <p><a href = "#frame3.html" target = "frame1"> Product Descriptions </a></p>

        <ol> 
            <li> Product 1 Description </li>
            <br>
            <li> Product 2 Description </li>
            <br>
            <li> Product 3 Description </li>
        </ol>

    </body>

</html> 

Frame 3 Code:

第 3 帧代码:

<!DOCTYPE html>
<html>

    <head> 
        <link rel = "stylesheet" href = "HTML_Style_Sheets.css">
    </head>

    <body>

        <h1> Contact Information </h1>

        <p> 4837 Blind Bay Road <br>
            Celista, BC V0E 1L0 <br>
            250-955-5462 <br>
        </p>

        <p> For any difficulties or questions you might have regarding out website and services please contact our Support Team. </p>

        <p> [email protected] </p>

        <h1> Hours of Operation </h1>
    </body>

</html>

So I want to do is to Link the Contact Information to the Frame 3. So that when you click on CONTACT INFORMATION from Frame 1..it should open that in Frame 3 . Same thing for Services. Once the services is Clicked in frame 1...it should display Services in Frame 3. (I still have to do the Services part but I have done the Contact Information part).

所以我想做的是将联系信息链接到第 3 帧。因此,当您单击 Frame 1 中的 CONTACT INFORMATION 时,它应该会在 Frame 3 中打开该信息。服务也是如此。一旦在框架 1 中单击服务...它应该在框架 3 中显示服务。(我仍然需要做服务部分,但我已经完成了联系信息部分)。

The problem:When i run it..and click on the Contact Information..It opens the FRAME3 in a new tab which is not what I have to do.

问题:当我运行它时..并单击联系信息..它会在新选项卡中打开 FRAME3,这不是我必须做的。

Yes I know its Huge but Please help me out with this.

是的,我知道它很大,但请帮我解决这个问题。

Thank You.

谢谢你。

回答by Johannes

In the <frame>tags inside the <frameset>tag you have to use the attribute namefor the frames, not ID, like this

<frame>标签内的<frameset>标签中,您必须使用name框架的属性,而不是ID,像这样

<frameset cols = "20%,50%">
     <frame src = "frame1.html" name = "frame1">
<frameset rows = "30%,30%">
    <frame src = "frame2.html" name = "frame2">
<frameset cols = "25%,25%">
    <frame src = "frame3.html" name = "frame3">
    <frame src = " ">

Then your link (inside frame1) should be like this:

那么你的链接(frame1 内)应该是这样的:

<a href = "frame3.html" target = "frame3">

(P.S.: If you needan ID, you can use both name andID)

(PS:如果需要ID的话,nameID都可以)

回答by Daniel Springer

Run this snippet!

运行这个片段!

<div id='top'><a href='#about'>Click me to go to About</a></div>

<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>





    <div id='about'>About. Click <a href="#top">here</a> to go back up.</div>

<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>