Reputation: 648
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
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
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