Kalim
Kalim

Reputation: 347

How to open a iframe link within the same iframe?

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?

Upvotes: 8

Views: 33542

Answers (5)

stefancarlton
stefancarlton

Reputation: 1727

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>

Upvotes: 1

Subir Kumar Sao
Subir Kumar Sao

Reputation: 8401

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>

Upvotes: 5

Kara
Kara

Reputation: 6226

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.

Upvotes: 0

Quentin
Quentin

Reputation: 943100

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.

Upvotes: 4

user1721135
user1721135

Reputation: 7092

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.

Upvotes: 0

Related Questions