Jquery wait before loading iframe

Hello, I use a button to change the src iframe when I click it like this:

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

Is there a way to show a "Wait" message or gif loader before loading a new URL?

+4
source share
2 answers

Why not use the jQuery.load function, which has a callback to control the 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!'); }); }) 
+5
source

the src property just sets the url for the frame, but the load function is supported by the jquery engine.so global ajax functions wait for the load () function to complete

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

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

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

this is the only way to display a β€œWait” message or gif loader until a new URL is loaded.

0
source

All Articles