How to open a iframe link within the same iframe?

江枫思渺然 提交于 2019-12-17 20:09:43

问题


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?


回答1:


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>



回答2:


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.




回答3:


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:


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.




回答5:


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>


来源:https://stackoverflow.com/questions/17802765/how-to-open-a-iframe-link-within-the-same-iframe

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!