How do I load an url in iframe with Jquery How do I load an url in iframe with Jquery jquery jquery

How do I load an url in iframe with Jquery


$("#button").click(function () {     $("#frame").attr("src", "http://www.example.com/");});

HTML:

 <div id="mydiv">     <iframe id="frame" src="" width="100%" height="300">     </iframe> </div> <button id="button">Load</button>


Try $(this).load("/file_name.html");. This method targets a local file.

You can also target remote files (on another domain) take a look at: http://en.wikipedia.org/wiki/Same_origin_policy


$("#frame").click(function () {     this.src="http://www.google.com/";});

Sometimes plain JavaScript is even cooler and faster than jQuery ;-)