如何将单个父 html 中的不同子 html 与第二个子 html 链接起来?

发布于 2024-12-24 21:56:18 字数 728 浏览 3 评论 0原文

首先,我是网页编程的新手,我似乎没有找到类似的问题来解决我试图弄清楚的情况。也许我没有使用正确的术语...

我有一个父 html 文件(House.html),基本上显示了两个 iframe(“房间”和“信息”),请参见下文。

House.html<br>
-iframe "room"<br>
-iframe "info"

iframe "room"<br>
-Room.html<br>
-->link "link_A"<br>
-->link "link_B"<br>

iframe "info"<br>
-A.html (some text)<br>
-B.html (some text)<br>

在“房间”iframe 中,我正在加载 Room.html,其中包含多个链接(link_A 和 link_B)。单击链接 (link_A) 应该将“info”iframe 更改为显示 A.html。再次单击 link_B 应该将“info”iframe 更改为显示 B.html。所有 html 页面都在同一个域中。

我了解如何将子级链接到父级,但我试图弄清楚如何在父级 html 页面内的特定 iframe 中从第三个 html 页面显示不同的 html 页面。

谁能指出我的答案吗?我是否需要在 House.html 中使用 if() 函数以及 link_A 或 link_B 中的目标值?

First, I am a new at webpage programming and I didn't seem to find a similar question to address the situation I am trying to figure out. Maybe I wasn't using the right terminology...

I have a parent html file (House.html) with essentially two iframes displayed ("room" and "info"), see below.

House.html<br>
-iframe "room"<br>
-iframe "info"

iframe "room"<br>
-Room.html<br>
-->link "link_A"<br>
-->link "link_B"<br>

iframe "info"<br>
-A.html (some text)<br>
-B.html (some text)<br>

Within the "room" iframe I am loading Room.html where there are multiple links contained (link_A and link_B). Clicking a link (link_A) is supposed to change "info" iframe to show A.html. Again, clicking link_B is supposed to change "info" iframe to show B.html. All html pages are on the same domain.

I understand how to link a child to a parent, but I am trying to figure out how to display different html pages in a specific iframe within a parent html page from a third html page.

Can anyone point me to an answer? Would I need to use an if() function in House.html and a target value from link_A or link_B?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

听不够的曲调 2024-12-31 21:56:18

来自 http://webdesign.about.com/ od/iframes/qt/target-links-iframes-and-frames.htm

当您在 IFRAME 中创建文档时,该框架中的任何链接都将在同一框架中自动打开。但是,通过链接上的目标属性(A 元素或 AREA 元素),您可以决定链接应在何处打开。
您可以选择使用 id 属性为 iframe 指定一个唯一的名称,然后将链接指向该框架,并将 ID 作为目标属性的值。

对于您的具体示例,它看起来像:

<a href="A.html" target="info">Page A</a>
<a href="B.html" target="info">Page B</a>

From http://webdesign.about.com/od/iframes/qt/target-links-iframes-and-frames.htm

When you create a document to be inside an IFRAME, any links in that frame will automatically open in that same frame. But with the target attribute on the link (the A element or AREA element) you can decide where your links should open.
You can choose to give your iframes a unique name with the id attribute and then point your links at that frame with the ID as the value of the target attribute.

For your specific example, it would look something like:

<a href="A.html" target="info">Page A</a>
<a href="B.html" target="info">Page B</a>
夏末染殇 2024-12-31 21:56:18

您可以使用 JavaScript 更改第二个 iframe 的 src 属性。您可以使用 jQuery 来做到这一点 - 例如将此代码放入 iframe1(未经测试)。

$('a').click( function() { 
  $('#iframe2', window.top.document).attr('src', 'new-src.html'); 
});

请注意,父页面和框架需要来自相同的域和子域(由于单源策略)。如果不是这种情况,您可能需要重新加载整个页面,方法是将 target="_top" 放入 iframe 内的链接中,并更改服务器端的 src。

You could use JavaScript to change the src attribute of the second iframe. You can do that with jQuery - e.g. put this code into iframe1 (untested).

$('a').click( function() { 
  $('#iframe2', window.top.document).attr('src', 'new-src.html'); 
});

Note that the parent page and the frames need to come from the same domain and subdomain (due to the single origin policy). If that's not the case, you would probably need to reload the whole page, by putting target="_top" in the link inside the iframe, and changing the src on the server side.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文