man_or_astroman
man_or_astroman

Reputation: 648

jquery wait until iframe is loaded

Hello, I'm using a button in order to change the src of an iframe when I click it this way:

$("#iframe").attr('src',"someurl");

Is there any way to display a "Please wait" message or a gif loader until the new URL is loaded?

Upvotes: 5

Views: 12573

Answers (2)

Bosco Michael
Bosco Michael

Reputation: 131

the src property just set the url for the frame but the load function is maintain by the jquery engine.so ajax global functions waits for load() function to complete

 $("#iframe").attr('src',"someurl");

First make sure the ajax event be asynchronous and use this,

 $('#iframe').load('someurl');

this is the only way to display a "Please wait" message or a gif loader until the new URL is loaded

Upvotes: 1

shershen
shershen

Reputation: 9993

Why not use jQuery.load function which has a callback for managing displayed text:

HTML

<button id="myLoadButton">Load</button>
<div id="Myiframe"></div>

JS

$('#myLoadButton').click(function(){
   $(this).text('Please wait...');
   $('#Myiframe').load('ajax/test.html', function(){
      $('#myLoadButton').text('Content loaded!');
   });
})

Upvotes: 5

Related Questions