2
  • I have a jsp page with iframe in it.

for example: worklist.jsp

 <html>
 <head>
 <body>
 <iframe height="15%" marginheight="0px" marginwidth="0px" scrolling="no" src="menuBanner.jsp" style="border:0; padding: 0px; position:absolute;" width="960px">
</iframe>
<div><button data-dojo-type="dijit.form.Button" value="Reload" id="reload"  onclick="reload();">Reload</button></div>
</body></head></html>
  • On click of a button, i need to reload only iframe page.
  • I tried the below script, but its reloading the whole page(worklist.jsp)

function reload(){ location.reload(); }

Rachel
  • 1,131
  • 11
  • 26
  • 43

4 Answers4

3

You can update/refresh the iframe by setting the src to the current src.

Here is an example.

var test = document.getElementById('iframeId');
test.src = iframe.src;

This way works for cross domain. The example in the comments are less hacky if iFrames are on the same domain.

CharliePrynn
  • 3,034
  • 5
  • 40
  • 68
2
function reload( {
  document.getElementById('iFrameID').contentDocument.location.reload(true);
}
dirkk
  • 6,160
  • 5
  • 33
  • 51
1

you can try:

var iframe = document.getElementById('YourIFrameId');
iframe.src = iframe.src + '?c=' + Math.random(); 

i think without changing the src attribute you will not be able to reload your iframe.

Behrad Farsi
  • 1,110
  • 13
  • 25
0

You can do like this. Get the iframe src and assign again to the src of the iframe

<script>
function test()
  {
    $('#subpage_frame').attr('src',$('#subpage_frame').attr('src')) ;
  }
</script>

<iframe src="test.com" onload="Loaded();" id="subpage_frame"></iframe>

<button onclick="test();">Refresh button</button>
Hari
  • 310
  • 3
  • 14