Open link in iframe

Viewed 291032

I have a Webpage with an iframe in it.

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

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

How can web links be displayed in a frame?

7 Answers

Assuming the iFrame has a name attribute of "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.

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.

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