Html 在 iframe 中打开链接

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/740816/
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-28 23:36:01  来源:igfitidea点击:

open link in iframe

htmliframe

提问by Anthony

I have a page with a frame in it, and some links below the frame.

我有一个带有框架的页面,框架下方还有一些链接。

I want the links, when clicked, to open the page in the frame.

我希望链接在单击时打开框架中的页面。

I tried <a href="" target="nameofframe">link1</a>but it didnt' work?

我试过了,<a href="" target="nameofframe">link1</a>但没有用?

updateits an iframe.

更新它的 iframe。

回答by Anthony

Assuming the iFrame has a name attribute of "myIframe":

假设 iFrame 的名称属性为“myIframe”:

<a href="http://www.google.com" target="myIframe">Link Text</a> 

You can also accomplish this with the use of Javascript. The iFrame has a src attribute which specifies the location it shows. As such, it's a simple matter of binding the click of a link to changing that src attribute.

您也可以使用 Javascript 来完成此操作。iFrame 有一个 src 属性,用于指定它显示的位置。因此,将链接的单击绑定到更改该 src 属性是一件简单的事情。

回答by jthompson

Try this:

尝试这个:

<iframe name="iframe1" src="target.html"></iframe>

<a href="link.html" target="iframe1">link</a>

The "target" attribute should open in the iframe.

“目标”属性应该在 iframe 中打开。

回答by Ospite

Use attribute name.

使用属性名称。

Here you can find the solution ("Use iframe as a Target for a Link"): http://www.w3schools.com/html/html_iframe.asp

在这里您可以找到解决方案(“使用 iframe 作为链接的目标”):http: //www.w3schools.com/html/html_iframe.asp

回答by Alix Axel

<a href="YOUR_URL" target="_YOUR_IFRAME_NAME">LINK NAME</a>

回答by bob

Because the target of the link matches the name of the iframe, the link will open in the iframe. Try this:

由于链接的目标与 iframe 的名称匹配,因此链接将在 iframe 中打开。尝试这个:

<iframe src="http://stackoverflow.com/" name="iframe_a">
<p>Your browser does not support iframes.</p>
</iframe>

<a href="http://www.cnn.com" target="iframe_a">www.cnn.com</a>

回答by Karthik Eyan

Well, there's an alternate way! You can use a button instead of hyperlink. Hence, when the button is clicked the web page specified in "name_of_webpage" is opened in the target frame named "name_of_iframe". It works for me!

嗯,有另一种方式!您可以使用按钮代替超链接。因此,当单击按钮时,在名为“name_of_iframe”的目标框架中打开“name_of_webpage”中指定的网页。这个对我有用!

<form method="post" action="name_of_webpage" target="name_of_iframe">
<input type="submit" value="any_name_you_want" />
</form>
<iframe name="name_of_iframe"></iframe>

回答by john smith

I had this problem in a project this morning. Make sure you specify the base tag in the head section.

今天早上我在一个项目中遇到了这个问题。确保在 head 部分中指定了 base 标签。

It should be like this:

应该是这样的:

<head>
<base target="name_of_iframe">
</head>

That way when you click a link on the page it will open up inside of the iframe by default.

这样,当您单击页面上的链接时,默认情况下它将在 iframe 内打开。

Hope that helped.

希望有所帮助。