How to open a iframe link within the same iframe?

2019-01-19 17:44发布

I have to load outside server URL within iframe which has some links, when user clicks on a link it opens outside the iframe. But I want to open it within the same iframe.

How is it possible?

标签: html iframe
5条回答
三岁会撩人
2楼-- · 2019-01-19 17:58

You will need to set the target=_self attribute in the link like this:

<a href="http://google.com/" target="_self">Google</a>

but if you are loading an external website you have no control over this may not be possible.

查看更多
\"骚年 ilove
3楼-- · 2019-01-19 18:04

You can not influence an iframe with a source on a different domain.

If it was on the same domain you could remove the target blank with javascript, but since its in a different domain you have no influence over the html.

Hope that helps and saves you countless hours trying the impossible.

查看更多
三岁会撩人
4楼-- · 2019-01-19 18:05

You should specify target name of the iframe.

<iframe src="demo_iframe.htm" name="iframe_a"></iframe>
<p><a href="http://www.w3schools.com" target="iframe_a">www.google.com</a></p>
查看更多
叼着烟拽天下
5楼-- · 2019-01-19 18:05

Links in documents loaded in iframes will, by default, open in the same frame.

If the document overrides that default behaviour (e.g. with target="_top") then the document will load elsewhere.

There is no way for the document containing the frame to change that behaviour (of the document loaded into the frame) if it is from an "outside server" since security restrictions prevent interaction with the DOM of documents form other origins.

查看更多
乱世女痞
6楼-- · 2019-01-19 18:07

checkout the _target attribute on a hyperlink: http://www.w3schools.com/tags/att_a_target.asp you want "_self" e.g.

<a href="#" target="_self">link</a>
查看更多
登录 后发表回答