Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I load an url in iframe with Jquery

I want to load an iframe on click, this is what I have so far:

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

It doesn't work. This is the complete code: JS Bin

like image 783
Youss Avatar asked Aug 24 '11 14:08

Youss


People also ask

Can you use jQuery in an iframe?

However, it's also possible to use a really simple jQuery to access the elements within the iFrame. Check it out below: $(document). ready(function(){ var iFrameDOM = $("iframe#frameID").

How do I fix refused connection in iframe?

You cannot fix this from Power Apps Portal side. Most probably web site that you try to embed as an iframe doesn't allow to be embedded. You need to update X-Frame-Options on the website that you are trying to embed to allow your Power Apps Portal (if you have control over that website).

How can get iframe HTML using jQuery?

# jQuery Code to Get HTML Content of IFrame$("#myButton"). on('click', function() { alert($("#myIframe"). contents(). find("html").


2 Answers

$("#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> 
like image 158
Dogbert Avatar answered Nov 12 '22 17:11

Dogbert


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

like image 23
Chris Avatar answered Nov 12 '22 17:11

Chris