1

I have the following code which can successfully change the iframe src with a button. How can I replace the button with a textlink?

<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>

<input type="button" id="changeframe" value="Change">

<iframe id="declinedframe" class="embed-responsive-item" src="http://forgezilla.com" height="585" width="100%" ></iframe>

// Go Last since changeframe hasn't exist yet.
<script>
  $('#changeframe').click(function () {
      $('#declinedframe').attr('src', 'http://stackoverflow.com');
  });
</script>
Arya
  • 8,473
  • 27
  • 105
  • 175

2 Answers2

1

You don't need jQuery or JavaScript to accomplish what you want to do, you only need HTML.

  • On <a>nchor add href="http://whatever.com/path/to/new/site.html" and target="nameOfIframe"

  • On <iframe> add name="nameOfIframe"

Snippet

<a href="http://stackoverflow.com" target="declinedframe">Change</a>

<iframe name="declinedframe" src="http://forgezilla.com" height="585" width="100%"></iframe>
Community
  • 1
  • 1
zer00ne
  • 41,936
  • 6
  • 41
  • 68
0

just replce

<input type="button" id="changeframe" value="Change">

with

<a href="#" id="changeframe">Change</a>

This should work

Abhishek Sharma
  • 2,485
  • 1
  • 21
  • 35