2

I got an assignment to build a website and I was wondering, how can I change a iframe on clicking a link without using javascript or giving the iframe a ID? I'd rather do it with a ID aswell, but yeah, that's not allowed.

Brino
  • 2,442
  • 1
  • 21
  • 36
iSidle
  • 121
  • 10
  • no you can't modify the ` – Marc B Nov 16 '15 at 17:36
  • 1
    No need for JavaScript at all, see http://stackoverflow.com/questions/740816/open-link-in-iframe – JCOC611 Nov 16 '15 at 17:37
  • Possible duplicate of [How to make a target link to an iframe also scroll to it?](http://stackoverflow.com/questions/13652363/how-to-make-a-target-link-to-an-iframe-also-scroll-to-it) – MaxZoom Nov 16 '15 at 17:38
  • @MaxZoom more a duplicate of the one JCOC611 shared: [open link in iframe](http://stackoverflow.com/questions/740816/open-link-in-iframe) – Andrew Mairose Nov 16 '15 at 17:42

1 Answers1

3

You can use an html link outside of the iframe, and set the target to the name of the iframe.

See the w3schools Example Here

<iframe src="demo_iframe.htm" name="iframe_a"></iframe>
<p><a href="http://www.w3schools.com" target="iframe_a">W3Schools.com</a></p>

If the link is inside the iframe, you simply need to set target=_self on the link.

<a href="http://www.w3schools.com" target="_self">W3Schools.com</a></p>
Brino
  • 2,442
  • 1
  • 21
  • 36
  • I'm currently using that method, but isn't that the same as giving that a ID? If not, what is the difference between the name and id attribute because I need solid arguments if I'm going to do it differently than they think it should be done. – iSidle Nov 16 '15 at 17:53
  • What do you mean by "differently than they think it should be done"? Your question states that you are not allowed to use ID. – Brino Nov 16 '15 at 18:07
  • ID is meant to be a unique identifier of an element in the DOM. Name is intended to identify the labels for form elements as seen in the POST, and also to identify the target of a form or hyperlink. See here: http://www.w3schools.com/tags/att_iframe_name.asp – Brino Nov 16 '15 at 18:12
  • Alright, it should be fine then, thank you for your help! – iSidle Nov 16 '15 at 18:30