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
  • 7,765
  • 24
  • 86
  • 160

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
  • 36,692
  • 5
  • 39
  • 58
0

just replce

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

with

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

This should work

Abhishek Sharma
  • 2,030
  • 19
  • 31