What’s the best way to reload / refresh an iframe?
I would like to reload an <iframe>
using JavaScript. The best way I found until now was set the iframe’s src
attribute to itself, but this isn’t very clean. Any ideas?
javascript iframe
add a comment |
I would like to reload an <iframe>
using JavaScript. The best way I found until now was set the iframe’s src
attribute to itself, but this isn’t very clean. Any ideas?
javascript iframe
3
Is there a reason why setting thesrc
attribute to itself isn't clean? It seems to be the only solution that works across browsers and across domains
– mirhagk
Sep 22 '15 at 18:21
add a comment |
I would like to reload an <iframe>
using JavaScript. The best way I found until now was set the iframe’s src
attribute to itself, but this isn’t very clean. Any ideas?
javascript iframe
I would like to reload an <iframe>
using JavaScript. The best way I found until now was set the iframe’s src
attribute to itself, but this isn’t very clean. Any ideas?
javascript iframe
javascript iframe
edited Aug 31 '17 at 7:33
Xufox
10.1k62848
10.1k62848
asked Sep 17 '08 at 19:00
caffocaffo
1,2382910
1,2382910
3
Is there a reason why setting thesrc
attribute to itself isn't clean? It seems to be the only solution that works across browsers and across domains
– mirhagk
Sep 22 '15 at 18:21
add a comment |
3
Is there a reason why setting thesrc
attribute to itself isn't clean? It seems to be the only solution that works across browsers and across domains
– mirhagk
Sep 22 '15 at 18:21
3
3
Is there a reason why setting the
src
attribute to itself isn't clean? It seems to be the only solution that works across browsers and across domains– mirhagk
Sep 22 '15 at 18:21
Is there a reason why setting the
src
attribute to itself isn't clean? It seems to be the only solution that works across browsers and across domains– mirhagk
Sep 22 '15 at 18:21
add a comment |
21 Answers
21
active
oldest
votes
document.getElementById('some_frame_id').contentWindow.location.reload();
be careful, in Firefox, window.frames
cannot be indexed by id, but by name or index
84
This won't work if it is not on the same domain.
– aemkei
Nov 4 '08 at 17:51
18
Actually, this approach didn't work for me in Chrome. There was no 'contentWindow' property. Though it was possible to use document.getElementById('some_frame_id').location.reload(); The method that worked for both FF and Chrome was document.getElementById('iframeid').src = document.getElementById('iframeid').src
– Mike Bevz
Aug 11 '11 at 13:09
1
@MikeBevz can location.reload is also accessible using Jquery selector?
– Jitender Mahlawat
Nov 21 '12 at 10:11
1
absolute it's work, but stuck with same domain origin policy ==a
– Bobby Stenly
Mar 19 '13 at 6:32
6
frames[1].location.href.reload()
andwindow.frames['some_frame_id'].location.href.reload()
can also be used
– Daniël W. Crompton
Sep 28 '13 at 8:53
|
show 8 more comments
document.getElementById('iframeid').src = document.getElementById('iframeid').src
It will reload the iframe
, even across domains!
Tested with IE7/8, Firefox and Chrome.
61
document.getElementById('iframeid').src += '';
also works: jsfiddle.net/Daniel_Hug/dWm5k
– Web_Designer
Feb 12 '12 at 6:44
3
It worked with Chrome before, but now stopped working with Chrome 19...
– Tarlog
Jun 18 '12 at 9:54
3
And what exactly do you do if the iframe's source has changed since it was added to the page?
– Niet the Dark Absol
Oct 11 '12 at 15:17
4
not working....
– Bobby Stenly
Mar 19 '13 at 6:33
7
Note that if the iframe src has a hash in it (e.g.http://example.com/#something
), this won't reload the frame. I've used the approach of adding a throwaway query parameter like?v2
to the URL before the hash.
– user85461
Feb 19 '15 at 4:21
|
show 4 more comments
If using jQuery, this seems to work:
$('#your_iframe').attr('src', $('#your_iframe').attr('src'));
I hope it's not too ugly for stackoverflow.
6
This, without jQuery:var iframe = document.getElementById("your_iframe"); iframe.src = src;
– Seagrass
Jul 14 '14 at 19:20
Please note to any future people that this (and the plain js solution) are the best to use, as it's cross platform and works across domains.
– mirhagk
Sep 22 '15 at 18:18
9
@Seagrass I think you mean:var iframe = document.getElementById("your_iframe"); iframe.src = iframe.src;
– maxisme
Feb 14 '16 at 1:33
@Maximilian thanks for the correction, you're right
– Seagrass
Feb 17 '16 at 14:36
add a comment |
window.frames['frameNameOrIndex'].location.reload();
9
it's work only if you have the same domain for the iframe
– Bobby Stenly
Mar 19 '13 at 6:34
add a comment |
Add empty space also reload the iFrame automatically.
document.getElementById('id').src += '';
add a comment |
Because of the same origin policy, this won't work when modifying an iframe pointing to a different domain. If you can target newer browsers, consider using HTML5's Cross-document messaging. You view the browsers that support this feature here: http://caniuse.com/#feat=x-doc-messaging.
If you can't use HTML5 functionality, then you can follow the tricks outlined here: http://softwareas.com/cross-domain-communication-with-iframes. That blog entry also does a good job of defining the problem.
add a comment |
A refinement on yajra's post ... I like the thought, but hate the idea of browser detection.
I rather take ppk's view of using object detection instead of browser detection,
(http://www.quirksmode.org/js/support.html),
because then you're actually testing the capabilities of the browser and acting accordingly, rather than what you think the browser is capable of at that time. Also doesn't require so much ugly browser ID string parsing, and doesn't exclude perfectly capable browsers of which you know nothing about.
So, instead of looking at navigator.AppName, why not do something like this, actually testing for the elements you use? (You could use try {} blocks if you want to get even fancier, but this worked for me.)
function reload_message_frame() {
var frame_id = 'live_message_frame';
if(window.document.getElementById(frame_id).location ) {
window.document.getElementById(frame_id).location.reload(true);
} else if (window.document.getElementById(frame_id).contentWindow.location ) {
window.document.getElementById(frame_id).contentWindow.location.reload(true);
} else if (window.document.getElementById(frame_id).src){
window.document.getElementById(frame_id).src = window.document.getElementById(frame_id).src;
} else {
// fail condition, respond as appropriate, or do nothing
alert("Sorry, unable to reload that frame!");
}
}
This way, you can go try as many different permutations as you like or is necessary, without causing javascript errors, and do something sensible if all else fails. It's a little more work to test for your objects before using them, but, IMO, makes for better and more failsafe code.
Worked for me in IE8, Firefox (15.0.1), Chrome (21.0.1180.89 m), and Opera (12.0.2) on Windows.
Maybe I could do even better by actually testing for the reload function, but that's enough for me right now. :)
add a comment |
I've just come up against this in chrome and the only thing that worked was removing and replacing the iframe. Example:
$(".iframe_wrapper").find("iframe").remove();
var iframe = $('<iframe src="' + src + '" frameborder="0"></iframe>');
$.find(".iframe_wrapper").append(iframe);
Pretty simple, not covered in the other answers.
add a comment |
for new url
location.assign("http:google.com");
The assign() method loads a new document.
reload
location.reload();
The reload() method is used to reload the current document.
add a comment |
Simply replacing the src
attribute of the iframe element was not satisfactory in my case because one would see the old content until the new page is loaded. This works better if you want to give instant visual feedback:
var url = iframeEl.src;
iframeEl.src = 'about:blank';
setTimeout(function() {
iframeEl.src = url;
}, 10);
I've just tested the same approach but without setTimeout - and it worked for me. actually, just iframe.setAttribute('src', iframe.getAttribute('src'))
– bonbonez
May 11 '16 at 15:56
add a comment |
In IE8 using .Net, setting the iframe.src
for the first time is ok,
but setting the iframe.src
for the second time is not raising the page_load
of the iframed page.
To solve it i used iframe.contentDocument.location.href = "NewUrl.htm"
.
Discover it when used jQuery thickBox and tried to reopen same page in the thickbox iframe.
Then it just showed the earlier page that was opened.
you just saved my bacon with that one - awesome
– Dr. Frankenstein
May 7 '10 at 13:25
anytime yaya ..
– Shaulian
Jun 6 '10 at 20:26
add a comment |
Use reload for IE and set src for other browsers. (reload does not work on FF)
tested on IE 7,8,9 and Firefox
if(navigator.appName == "Microsoft Internet Explorer"){
window.document.getElementById('iframeId').contentWindow.location.reload(true);
}else {
window.document.getElementById('iframeId').src = window.document.getElementById('iframeId').src;
}
This seemed to work fine on Firefox for me.
– Matt Browne
Mar 16 '12 at 18:18
add a comment |
Have you considered appending to the url a meaningless query string parameter?
<iframe src="myBaseURL.com/something/" />
<script>
var i = document.getElementsById("iframe")[0],
src = i.src,
number = 1;
//For an update
i.src = src + "?ignoreMe=" + number;
number++;
</script>
It won't be seen & if you are aware of the parameter being safe then it should be fine.
add a comment |
If you using Jquery then there is one line code.
$('#iframeID',window.parent.document).attr('src',$('#iframeID',window.parent.document).attr('src'));
and if you are working with same parent then
$('#iframeID',parent.document).attr('src',$('#iframeID',parent.document).attr('src'));
add a comment |
If all of the above doesn't work for you:
window.location.reload();
This for some reason refreshed my iframe instead of the whole script. Maybe because it is placed in the frame itself, while all those getElemntById solutions work when you try to refresh a frame from another frame?
Or I don't understand this fully and talk gibberish, anyways this worked for me like a charm :)
add a comment |
Using self.location.reload()
will reload the iframe.
<iframe src="https://vivekkumar11432.wordpress.com/" width="300" height="300"></iframe>
<br><br>
<input type='button' value="Reload" onclick="self.location.reload();" />
add a comment |
Now to make this work on chrome 66, try this:
const reloadIframe = (iframeId) => {
const el = document.getElementById(iframeId)
const src = el.src
el.src = ''
setTimeout(() => {
el.src = src
})
}
add a comment |
<script type="text/javascript">
top.frames['DetailFrame'].location = top.frames['DetailFrame'].location;
</script>
1
Not the choice I would use but I guess it would do. With some additional code that you could have added in.
– transilvlad
Oct 21 '12 at 13:11
add a comment |
If you tried all of the other suggestions, and couldn't get any of them to work (like I couldn't), here's something you can try that may be useful.
HTML
<a class="refresh-this-frame" rel="#iframe-id-0">Refresh</a>
<iframe src="" id="iframe-id-0"></iframe>
JS
$('.refresh-this-frame').click(function() {
var thisIframe = $(this).attr('rel');
var currentState = $(thisIframe).attr('src');
function removeSrc() {
$(thisIframe).attr('src', '');
}
setTimeout (removeSrc, 100);
function replaceSrc() {
$(thisIframe).attr('src', currentState);
}
setTimeout (replaceSrc, 200);
});
I initially set out to try and save some time with RWD and cross-browser testing. I wanted to create a quick page that housed a bunch of iframes, organized into groups that I would show/hide at will. Logically you'd want to be able to easily and quickly refresh any given frame.
I should note that the project I am working on currently, the one in use in this test-bed, is a one-page site with indexed locations (e.g. index.html#home). That may have had something to do with why I couldn't get any of the other solutions to refresh my particular frame.
Having said that, I know it's not the cleanest thing in the world, but it works for my purposes. Hope this helps someone. Now if only I could figure out how to keep the iframe from scrolling the parent page each time there's animation inside iframe...
EDIT:
I realized that this doesn't "refresh" the iframe like I'd hoped it would. It will reload the iframe's initial source though. Still can't figure out why I couldn't get any of the other options to work..
UPDATE:
The reason I couldn't get any of the other methods to work is because I was testing them in Chrome, and Chrome won't allow you to access an iframe's content (Explanation: Is it likely that future releases of Chrome support contentWindow/contentDocument when iFrame loads a local html file from local html file?) if it doesn't originate from the same location (so far as I understand it). Upon further testing, I can't access contentWindow in FF either.
AMENDED JS
$('.refresh-this-frame').click(function() {
var targetID = $(this).attr('rel');
var targetSrc = $(targetID).attr('src');
var cleanID = targetID.replace("#","");
var chromeTest = ( navigator.userAgent.match(/Chrome/g) ? true : false );
var FFTest = ( navigator.userAgent.match(/Firefox/g) ? true : false );
if (chromeTest == true) {
function removeSrc() {
$(targetID).attr('src', '');
}
setTimeout (removeSrc, 100);
function replaceSrc() {
$(targetID).attr('src', targetSrc);
}
setTimeout (replaceSrc, 200);
}
if (FFTest == true) {
function removeSrc() {
$(targetID).attr('src', '');
}
setTimeout (removeSrc, 100);
function replaceSrc() {
$(targetID).attr('src', targetSrc);
}
setTimeout (replaceSrc, 200);
}
if (chromeTest == false && FFTest == false) {
var targetLoc = (document.getElementById(cleanID).contentWindow.location).toString();
function removeSrc() {
$(targetID).attr('src', '');
}
setTimeout (removeSrc, 100);
function replaceSrc2() {
$(targetID).attr('src', targetLoc);
}
setTimeout (replaceSrc2, 200);
}
});
add a comment |
For debugging purposes one could open the console change the execution context to the frame that he wants refreshed and do document.location.reload()
add a comment |
Another solution.
const frame = document.getElementById("my-iframe");
frame.parentNode.replaceChild(frame.cloneNode(), frame);
A disadvantage of that is modifies the root document DOM tree and will cause a repaint. I usedvar url = ifr.src; ifr.src = null; ifr.src = url;
– Pocketsand
Feb 27 '18 at 12:10
I think that reloading an iframe will always cause a repaint no matter of the code used.
– Vasile Alexandru Peşte
Mar 4 '18 at 21:45
add a comment |
21 Answers
21
active
oldest
votes
21 Answers
21
active
oldest
votes
active
oldest
votes
active
oldest
votes
document.getElementById('some_frame_id').contentWindow.location.reload();
be careful, in Firefox, window.frames
cannot be indexed by id, but by name or index
84
This won't work if it is not on the same domain.
– aemkei
Nov 4 '08 at 17:51
18
Actually, this approach didn't work for me in Chrome. There was no 'contentWindow' property. Though it was possible to use document.getElementById('some_frame_id').location.reload(); The method that worked for both FF and Chrome was document.getElementById('iframeid').src = document.getElementById('iframeid').src
– Mike Bevz
Aug 11 '11 at 13:09
1
@MikeBevz can location.reload is also accessible using Jquery selector?
– Jitender Mahlawat
Nov 21 '12 at 10:11
1
absolute it's work, but stuck with same domain origin policy ==a
– Bobby Stenly
Mar 19 '13 at 6:32
6
frames[1].location.href.reload()
andwindow.frames['some_frame_id'].location.href.reload()
can also be used
– Daniël W. Crompton
Sep 28 '13 at 8:53
|
show 8 more comments
document.getElementById('some_frame_id').contentWindow.location.reload();
be careful, in Firefox, window.frames
cannot be indexed by id, but by name or index
84
This won't work if it is not on the same domain.
– aemkei
Nov 4 '08 at 17:51
18
Actually, this approach didn't work for me in Chrome. There was no 'contentWindow' property. Though it was possible to use document.getElementById('some_frame_id').location.reload(); The method that worked for both FF and Chrome was document.getElementById('iframeid').src = document.getElementById('iframeid').src
– Mike Bevz
Aug 11 '11 at 13:09
1
@MikeBevz can location.reload is also accessible using Jquery selector?
– Jitender Mahlawat
Nov 21 '12 at 10:11
1
absolute it's work, but stuck with same domain origin policy ==a
– Bobby Stenly
Mar 19 '13 at 6:32
6
frames[1].location.href.reload()
andwindow.frames['some_frame_id'].location.href.reload()
can also be used
– Daniël W. Crompton
Sep 28 '13 at 8:53
|
show 8 more comments
document.getElementById('some_frame_id').contentWindow.location.reload();
be careful, in Firefox, window.frames
cannot be indexed by id, but by name or index
document.getElementById('some_frame_id').contentWindow.location.reload();
be careful, in Firefox, window.frames
cannot be indexed by id, but by name or index
edited Jan 30 '11 at 3:58
Yi Jiang
41.6k13123126
41.6k13123126
answered Sep 17 '08 at 19:36
Ed.Ed.
2,95021412
2,95021412
84
This won't work if it is not on the same domain.
– aemkei
Nov 4 '08 at 17:51
18
Actually, this approach didn't work for me in Chrome. There was no 'contentWindow' property. Though it was possible to use document.getElementById('some_frame_id').location.reload(); The method that worked for both FF and Chrome was document.getElementById('iframeid').src = document.getElementById('iframeid').src
– Mike Bevz
Aug 11 '11 at 13:09
1
@MikeBevz can location.reload is also accessible using Jquery selector?
– Jitender Mahlawat
Nov 21 '12 at 10:11
1
absolute it's work, but stuck with same domain origin policy ==a
– Bobby Stenly
Mar 19 '13 at 6:32
6
frames[1].location.href.reload()
andwindow.frames['some_frame_id'].location.href.reload()
can also be used
– Daniël W. Crompton
Sep 28 '13 at 8:53
|
show 8 more comments
84
This won't work if it is not on the same domain.
– aemkei
Nov 4 '08 at 17:51
18
Actually, this approach didn't work for me in Chrome. There was no 'contentWindow' property. Though it was possible to use document.getElementById('some_frame_id').location.reload(); The method that worked for both FF and Chrome was document.getElementById('iframeid').src = document.getElementById('iframeid').src
– Mike Bevz
Aug 11 '11 at 13:09
1
@MikeBevz can location.reload is also accessible using Jquery selector?
– Jitender Mahlawat
Nov 21 '12 at 10:11
1
absolute it's work, but stuck with same domain origin policy ==a
– Bobby Stenly
Mar 19 '13 at 6:32
6
frames[1].location.href.reload()
andwindow.frames['some_frame_id'].location.href.reload()
can also be used
– Daniël W. Crompton
Sep 28 '13 at 8:53
84
84
This won't work if it is not on the same domain.
– aemkei
Nov 4 '08 at 17:51
This won't work if it is not on the same domain.
– aemkei
Nov 4 '08 at 17:51
18
18
Actually, this approach didn't work for me in Chrome. There was no 'contentWindow' property. Though it was possible to use document.getElementById('some_frame_id').location.reload(); The method that worked for both FF and Chrome was document.getElementById('iframeid').src = document.getElementById('iframeid').src
– Mike Bevz
Aug 11 '11 at 13:09
Actually, this approach didn't work for me in Chrome. There was no 'contentWindow' property. Though it was possible to use document.getElementById('some_frame_id').location.reload(); The method that worked for both FF and Chrome was document.getElementById('iframeid').src = document.getElementById('iframeid').src
– Mike Bevz
Aug 11 '11 at 13:09
1
1
@MikeBevz can location.reload is also accessible using Jquery selector?
– Jitender Mahlawat
Nov 21 '12 at 10:11
@MikeBevz can location.reload is also accessible using Jquery selector?
– Jitender Mahlawat
Nov 21 '12 at 10:11
1
1
absolute it's work, but stuck with same domain origin policy ==a
– Bobby Stenly
Mar 19 '13 at 6:32
absolute it's work, but stuck with same domain origin policy ==a
– Bobby Stenly
Mar 19 '13 at 6:32
6
6
frames[1].location.href.reload()
and window.frames['some_frame_id'].location.href.reload()
can also be used– Daniël W. Crompton
Sep 28 '13 at 8:53
frames[1].location.href.reload()
and window.frames['some_frame_id'].location.href.reload()
can also be used– Daniël W. Crompton
Sep 28 '13 at 8:53
|
show 8 more comments
document.getElementById('iframeid').src = document.getElementById('iframeid').src
It will reload the iframe
, even across domains!
Tested with IE7/8, Firefox and Chrome.
61
document.getElementById('iframeid').src += '';
also works: jsfiddle.net/Daniel_Hug/dWm5k
– Web_Designer
Feb 12 '12 at 6:44
3
It worked with Chrome before, but now stopped working with Chrome 19...
– Tarlog
Jun 18 '12 at 9:54
3
And what exactly do you do if the iframe's source has changed since it was added to the page?
– Niet the Dark Absol
Oct 11 '12 at 15:17
4
not working....
– Bobby Stenly
Mar 19 '13 at 6:33
7
Note that if the iframe src has a hash in it (e.g.http://example.com/#something
), this won't reload the frame. I've used the approach of adding a throwaway query parameter like?v2
to the URL before the hash.
– user85461
Feb 19 '15 at 4:21
|
show 4 more comments
document.getElementById('iframeid').src = document.getElementById('iframeid').src
It will reload the iframe
, even across domains!
Tested with IE7/8, Firefox and Chrome.
61
document.getElementById('iframeid').src += '';
also works: jsfiddle.net/Daniel_Hug/dWm5k
– Web_Designer
Feb 12 '12 at 6:44
3
It worked with Chrome before, but now stopped working with Chrome 19...
– Tarlog
Jun 18 '12 at 9:54
3
And what exactly do you do if the iframe's source has changed since it was added to the page?
– Niet the Dark Absol
Oct 11 '12 at 15:17
4
not working....
– Bobby Stenly
Mar 19 '13 at 6:33
7
Note that if the iframe src has a hash in it (e.g.http://example.com/#something
), this won't reload the frame. I've used the approach of adding a throwaway query parameter like?v2
to the URL before the hash.
– user85461
Feb 19 '15 at 4:21
|
show 4 more comments
document.getElementById('iframeid').src = document.getElementById('iframeid').src
It will reload the iframe
, even across domains!
Tested with IE7/8, Firefox and Chrome.
document.getElementById('iframeid').src = document.getElementById('iframeid').src
It will reload the iframe
, even across domains!
Tested with IE7/8, Firefox and Chrome.
edited Jan 30 '11 at 3:59
Yi Jiang
41.6k13123126
41.6k13123126
answered Oct 31 '10 at 6:27
evkoevko
1,6611102
1,6611102
61
document.getElementById('iframeid').src += '';
also works: jsfiddle.net/Daniel_Hug/dWm5k
– Web_Designer
Feb 12 '12 at 6:44
3
It worked with Chrome before, but now stopped working with Chrome 19...
– Tarlog
Jun 18 '12 at 9:54
3
And what exactly do you do if the iframe's source has changed since it was added to the page?
– Niet the Dark Absol
Oct 11 '12 at 15:17
4
not working....
– Bobby Stenly
Mar 19 '13 at 6:33
7
Note that if the iframe src has a hash in it (e.g.http://example.com/#something
), this won't reload the frame. I've used the approach of adding a throwaway query parameter like?v2
to the URL before the hash.
– user85461
Feb 19 '15 at 4:21
|
show 4 more comments
61
document.getElementById('iframeid').src += '';
also works: jsfiddle.net/Daniel_Hug/dWm5k
– Web_Designer
Feb 12 '12 at 6:44
3
It worked with Chrome before, but now stopped working with Chrome 19...
– Tarlog
Jun 18 '12 at 9:54
3
And what exactly do you do if the iframe's source has changed since it was added to the page?
– Niet the Dark Absol
Oct 11 '12 at 15:17
4
not working....
– Bobby Stenly
Mar 19 '13 at 6:33
7
Note that if the iframe src has a hash in it (e.g.http://example.com/#something
), this won't reload the frame. I've used the approach of adding a throwaway query parameter like?v2
to the URL before the hash.
– user85461
Feb 19 '15 at 4:21
61
61
document.getElementById('iframeid').src += '';
also works: jsfiddle.net/Daniel_Hug/dWm5k– Web_Designer
Feb 12 '12 at 6:44
document.getElementById('iframeid').src += '';
also works: jsfiddle.net/Daniel_Hug/dWm5k– Web_Designer
Feb 12 '12 at 6:44
3
3
It worked with Chrome before, but now stopped working with Chrome 19...
– Tarlog
Jun 18 '12 at 9:54
It worked with Chrome before, but now stopped working with Chrome 19...
– Tarlog
Jun 18 '12 at 9:54
3
3
And what exactly do you do if the iframe's source has changed since it was added to the page?
– Niet the Dark Absol
Oct 11 '12 at 15:17
And what exactly do you do if the iframe's source has changed since it was added to the page?
– Niet the Dark Absol
Oct 11 '12 at 15:17
4
4
not working....
– Bobby Stenly
Mar 19 '13 at 6:33
not working....
– Bobby Stenly
Mar 19 '13 at 6:33
7
7
Note that if the iframe src has a hash in it (e.g.
http://example.com/#something
), this won't reload the frame. I've used the approach of adding a throwaway query parameter like ?v2
to the URL before the hash.– user85461
Feb 19 '15 at 4:21
Note that if the iframe src has a hash in it (e.g.
http://example.com/#something
), this won't reload the frame. I've used the approach of adding a throwaway query parameter like ?v2
to the URL before the hash.– user85461
Feb 19 '15 at 4:21
|
show 4 more comments
If using jQuery, this seems to work:
$('#your_iframe').attr('src', $('#your_iframe').attr('src'));
I hope it's not too ugly for stackoverflow.
6
This, without jQuery:var iframe = document.getElementById("your_iframe"); iframe.src = src;
– Seagrass
Jul 14 '14 at 19:20
Please note to any future people that this (and the plain js solution) are the best to use, as it's cross platform and works across domains.
– mirhagk
Sep 22 '15 at 18:18
9
@Seagrass I think you mean:var iframe = document.getElementById("your_iframe"); iframe.src = iframe.src;
– maxisme
Feb 14 '16 at 1:33
@Maximilian thanks for the correction, you're right
– Seagrass
Feb 17 '16 at 14:36
add a comment |
If using jQuery, this seems to work:
$('#your_iframe').attr('src', $('#your_iframe').attr('src'));
I hope it's not too ugly for stackoverflow.
6
This, without jQuery:var iframe = document.getElementById("your_iframe"); iframe.src = src;
– Seagrass
Jul 14 '14 at 19:20
Please note to any future people that this (and the plain js solution) are the best to use, as it's cross platform and works across domains.
– mirhagk
Sep 22 '15 at 18:18
9
@Seagrass I think you mean:var iframe = document.getElementById("your_iframe"); iframe.src = iframe.src;
– maxisme
Feb 14 '16 at 1:33
@Maximilian thanks for the correction, you're right
– Seagrass
Feb 17 '16 at 14:36
add a comment |
If using jQuery, this seems to work:
$('#your_iframe').attr('src', $('#your_iframe').attr('src'));
I hope it's not too ugly for stackoverflow.
If using jQuery, this seems to work:
$('#your_iframe').attr('src', $('#your_iframe').attr('src'));
I hope it's not too ugly for stackoverflow.
edited Dec 12 '13 at 22:12
Dave Jarvis
20.9k30130255
20.9k30130255
answered Oct 18 '11 at 15:29
lousygarualousygarua
56143
56143
6
This, without jQuery:var iframe = document.getElementById("your_iframe"); iframe.src = src;
– Seagrass
Jul 14 '14 at 19:20
Please note to any future people that this (and the plain js solution) are the best to use, as it's cross platform and works across domains.
– mirhagk
Sep 22 '15 at 18:18
9
@Seagrass I think you mean:var iframe = document.getElementById("your_iframe"); iframe.src = iframe.src;
– maxisme
Feb 14 '16 at 1:33
@Maximilian thanks for the correction, you're right
– Seagrass
Feb 17 '16 at 14:36
add a comment |
6
This, without jQuery:var iframe = document.getElementById("your_iframe"); iframe.src = src;
– Seagrass
Jul 14 '14 at 19:20
Please note to any future people that this (and the plain js solution) are the best to use, as it's cross platform and works across domains.
– mirhagk
Sep 22 '15 at 18:18
9
@Seagrass I think you mean:var iframe = document.getElementById("your_iframe"); iframe.src = iframe.src;
– maxisme
Feb 14 '16 at 1:33
@Maximilian thanks for the correction, you're right
– Seagrass
Feb 17 '16 at 14:36
6
6
This, without jQuery:
var iframe = document.getElementById("your_iframe"); iframe.src = src;
– Seagrass
Jul 14 '14 at 19:20
This, without jQuery:
var iframe = document.getElementById("your_iframe"); iframe.src = src;
– Seagrass
Jul 14 '14 at 19:20
Please note to any future people that this (and the plain js solution) are the best to use, as it's cross platform and works across domains.
– mirhagk
Sep 22 '15 at 18:18
Please note to any future people that this (and the plain js solution) are the best to use, as it's cross platform and works across domains.
– mirhagk
Sep 22 '15 at 18:18
9
9
@Seagrass I think you mean:
var iframe = document.getElementById("your_iframe"); iframe.src = iframe.src;
– maxisme
Feb 14 '16 at 1:33
@Seagrass I think you mean:
var iframe = document.getElementById("your_iframe"); iframe.src = iframe.src;
– maxisme
Feb 14 '16 at 1:33
@Maximilian thanks for the correction, you're right
– Seagrass
Feb 17 '16 at 14:36
@Maximilian thanks for the correction, you're right
– Seagrass
Feb 17 '16 at 14:36
add a comment |
window.frames['frameNameOrIndex'].location.reload();
9
it's work only if you have the same domain for the iframe
– Bobby Stenly
Mar 19 '13 at 6:34
add a comment |
window.frames['frameNameOrIndex'].location.reload();
9
it's work only if you have the same domain for the iframe
– Bobby Stenly
Mar 19 '13 at 6:34
add a comment |
window.frames['frameNameOrIndex'].location.reload();
window.frames['frameNameOrIndex'].location.reload();
edited Jan 30 '11 at 3:59
Yi Jiang
41.6k13123126
41.6k13123126
answered Sep 17 '08 at 19:01
scunliffescunliffe
47.9k19106145
47.9k19106145
9
it's work only if you have the same domain for the iframe
– Bobby Stenly
Mar 19 '13 at 6:34
add a comment |
9
it's work only if you have the same domain for the iframe
– Bobby Stenly
Mar 19 '13 at 6:34
9
9
it's work only if you have the same domain for the iframe
– Bobby Stenly
Mar 19 '13 at 6:34
it's work only if you have the same domain for the iframe
– Bobby Stenly
Mar 19 '13 at 6:34
add a comment |
Add empty space also reload the iFrame automatically.
document.getElementById('id').src += '';
add a comment |
Add empty space also reload the iFrame automatically.
document.getElementById('id').src += '';
add a comment |
Add empty space also reload the iFrame automatically.
document.getElementById('id').src += '';
Add empty space also reload the iFrame automatically.
document.getElementById('id').src += '';
edited Oct 24 '17 at 10:12
answered Oct 24 '17 at 4:38
Yohanes AIYohanes AI
1,18142958
1,18142958
add a comment |
add a comment |
Because of the same origin policy, this won't work when modifying an iframe pointing to a different domain. If you can target newer browsers, consider using HTML5's Cross-document messaging. You view the browsers that support this feature here: http://caniuse.com/#feat=x-doc-messaging.
If you can't use HTML5 functionality, then you can follow the tricks outlined here: http://softwareas.com/cross-domain-communication-with-iframes. That blog entry also does a good job of defining the problem.
add a comment |
Because of the same origin policy, this won't work when modifying an iframe pointing to a different domain. If you can target newer browsers, consider using HTML5's Cross-document messaging. You view the browsers that support this feature here: http://caniuse.com/#feat=x-doc-messaging.
If you can't use HTML5 functionality, then you can follow the tricks outlined here: http://softwareas.com/cross-domain-communication-with-iframes. That blog entry also does a good job of defining the problem.
add a comment |
Because of the same origin policy, this won't work when modifying an iframe pointing to a different domain. If you can target newer browsers, consider using HTML5's Cross-document messaging. You view the browsers that support this feature here: http://caniuse.com/#feat=x-doc-messaging.
If you can't use HTML5 functionality, then you can follow the tricks outlined here: http://softwareas.com/cross-domain-communication-with-iframes. That blog entry also does a good job of defining the problem.
Because of the same origin policy, this won't work when modifying an iframe pointing to a different domain. If you can target newer browsers, consider using HTML5's Cross-document messaging. You view the browsers that support this feature here: http://caniuse.com/#feat=x-doc-messaging.
If you can't use HTML5 functionality, then you can follow the tricks outlined here: http://softwareas.com/cross-domain-communication-with-iframes. That blog entry also does a good job of defining the problem.
answered Oct 8 '10 at 0:02
big lepbig lep
65655
65655
add a comment |
add a comment |
A refinement on yajra's post ... I like the thought, but hate the idea of browser detection.
I rather take ppk's view of using object detection instead of browser detection,
(http://www.quirksmode.org/js/support.html),
because then you're actually testing the capabilities of the browser and acting accordingly, rather than what you think the browser is capable of at that time. Also doesn't require so much ugly browser ID string parsing, and doesn't exclude perfectly capable browsers of which you know nothing about.
So, instead of looking at navigator.AppName, why not do something like this, actually testing for the elements you use? (You could use try {} blocks if you want to get even fancier, but this worked for me.)
function reload_message_frame() {
var frame_id = 'live_message_frame';
if(window.document.getElementById(frame_id).location ) {
window.document.getElementById(frame_id).location.reload(true);
} else if (window.document.getElementById(frame_id).contentWindow.location ) {
window.document.getElementById(frame_id).contentWindow.location.reload(true);
} else if (window.document.getElementById(frame_id).src){
window.document.getElementById(frame_id).src = window.document.getElementById(frame_id).src;
} else {
// fail condition, respond as appropriate, or do nothing
alert("Sorry, unable to reload that frame!");
}
}
This way, you can go try as many different permutations as you like or is necessary, without causing javascript errors, and do something sensible if all else fails. It's a little more work to test for your objects before using them, but, IMO, makes for better and more failsafe code.
Worked for me in IE8, Firefox (15.0.1), Chrome (21.0.1180.89 m), and Opera (12.0.2) on Windows.
Maybe I could do even better by actually testing for the reload function, but that's enough for me right now. :)
add a comment |
A refinement on yajra's post ... I like the thought, but hate the idea of browser detection.
I rather take ppk's view of using object detection instead of browser detection,
(http://www.quirksmode.org/js/support.html),
because then you're actually testing the capabilities of the browser and acting accordingly, rather than what you think the browser is capable of at that time. Also doesn't require so much ugly browser ID string parsing, and doesn't exclude perfectly capable browsers of which you know nothing about.
So, instead of looking at navigator.AppName, why not do something like this, actually testing for the elements you use? (You could use try {} blocks if you want to get even fancier, but this worked for me.)
function reload_message_frame() {
var frame_id = 'live_message_frame';
if(window.document.getElementById(frame_id).location ) {
window.document.getElementById(frame_id).location.reload(true);
} else if (window.document.getElementById(frame_id).contentWindow.location ) {
window.document.getElementById(frame_id).contentWindow.location.reload(true);
} else if (window.document.getElementById(frame_id).src){
window.document.getElementById(frame_id).src = window.document.getElementById(frame_id).src;
} else {
// fail condition, respond as appropriate, or do nothing
alert("Sorry, unable to reload that frame!");
}
}
This way, you can go try as many different permutations as you like or is necessary, without causing javascript errors, and do something sensible if all else fails. It's a little more work to test for your objects before using them, but, IMO, makes for better and more failsafe code.
Worked for me in IE8, Firefox (15.0.1), Chrome (21.0.1180.89 m), and Opera (12.0.2) on Windows.
Maybe I could do even better by actually testing for the reload function, but that's enough for me right now. :)
add a comment |
A refinement on yajra's post ... I like the thought, but hate the idea of browser detection.
I rather take ppk's view of using object detection instead of browser detection,
(http://www.quirksmode.org/js/support.html),
because then you're actually testing the capabilities of the browser and acting accordingly, rather than what you think the browser is capable of at that time. Also doesn't require so much ugly browser ID string parsing, and doesn't exclude perfectly capable browsers of which you know nothing about.
So, instead of looking at navigator.AppName, why not do something like this, actually testing for the elements you use? (You could use try {} blocks if you want to get even fancier, but this worked for me.)
function reload_message_frame() {
var frame_id = 'live_message_frame';
if(window.document.getElementById(frame_id).location ) {
window.document.getElementById(frame_id).location.reload(true);
} else if (window.document.getElementById(frame_id).contentWindow.location ) {
window.document.getElementById(frame_id).contentWindow.location.reload(true);
} else if (window.document.getElementById(frame_id).src){
window.document.getElementById(frame_id).src = window.document.getElementById(frame_id).src;
} else {
// fail condition, respond as appropriate, or do nothing
alert("Sorry, unable to reload that frame!");
}
}
This way, you can go try as many different permutations as you like or is necessary, without causing javascript errors, and do something sensible if all else fails. It's a little more work to test for your objects before using them, but, IMO, makes for better and more failsafe code.
Worked for me in IE8, Firefox (15.0.1), Chrome (21.0.1180.89 m), and Opera (12.0.2) on Windows.
Maybe I could do even better by actually testing for the reload function, but that's enough for me right now. :)
A refinement on yajra's post ... I like the thought, but hate the idea of browser detection.
I rather take ppk's view of using object detection instead of browser detection,
(http://www.quirksmode.org/js/support.html),
because then you're actually testing the capabilities of the browser and acting accordingly, rather than what you think the browser is capable of at that time. Also doesn't require so much ugly browser ID string parsing, and doesn't exclude perfectly capable browsers of which you know nothing about.
So, instead of looking at navigator.AppName, why not do something like this, actually testing for the elements you use? (You could use try {} blocks if you want to get even fancier, but this worked for me.)
function reload_message_frame() {
var frame_id = 'live_message_frame';
if(window.document.getElementById(frame_id).location ) {
window.document.getElementById(frame_id).location.reload(true);
} else if (window.document.getElementById(frame_id).contentWindow.location ) {
window.document.getElementById(frame_id).contentWindow.location.reload(true);
} else if (window.document.getElementById(frame_id).src){
window.document.getElementById(frame_id).src = window.document.getElementById(frame_id).src;
} else {
// fail condition, respond as appropriate, or do nothing
alert("Sorry, unable to reload that frame!");
}
}
This way, you can go try as many different permutations as you like or is necessary, without causing javascript errors, and do something sensible if all else fails. It's a little more work to test for your objects before using them, but, IMO, makes for better and more failsafe code.
Worked for me in IE8, Firefox (15.0.1), Chrome (21.0.1180.89 m), and Opera (12.0.2) on Windows.
Maybe I could do even better by actually testing for the reload function, but that's enough for me right now. :)
answered Sep 15 '12 at 6:58
Aaron WallentineAaron Wallentine
1,1221117
1,1221117
add a comment |
add a comment |
I've just come up against this in chrome and the only thing that worked was removing and replacing the iframe. Example:
$(".iframe_wrapper").find("iframe").remove();
var iframe = $('<iframe src="' + src + '" frameborder="0"></iframe>');
$.find(".iframe_wrapper").append(iframe);
Pretty simple, not covered in the other answers.
add a comment |
I've just come up against this in chrome and the only thing that worked was removing and replacing the iframe. Example:
$(".iframe_wrapper").find("iframe").remove();
var iframe = $('<iframe src="' + src + '" frameborder="0"></iframe>');
$.find(".iframe_wrapper").append(iframe);
Pretty simple, not covered in the other answers.
add a comment |
I've just come up against this in chrome and the only thing that worked was removing and replacing the iframe. Example:
$(".iframe_wrapper").find("iframe").remove();
var iframe = $('<iframe src="' + src + '" frameborder="0"></iframe>');
$.find(".iframe_wrapper").append(iframe);
Pretty simple, not covered in the other answers.
I've just come up against this in chrome and the only thing that worked was removing and replacing the iframe. Example:
$(".iframe_wrapper").find("iframe").remove();
var iframe = $('<iframe src="' + src + '" frameborder="0"></iframe>');
$.find(".iframe_wrapper").append(iframe);
Pretty simple, not covered in the other answers.
edited Nov 14 '12 at 4:32
answered Aug 1 '12 at 16:09
Liam MLiam M
3,64822549
3,64822549
add a comment |
add a comment |
for new url
location.assign("http:google.com");
The assign() method loads a new document.
reload
location.reload();
The reload() method is used to reload the current document.
add a comment |
for new url
location.assign("http:google.com");
The assign() method loads a new document.
reload
location.reload();
The reload() method is used to reload the current document.
add a comment |
for new url
location.assign("http:google.com");
The assign() method loads a new document.
reload
location.reload();
The reload() method is used to reload the current document.
for new url
location.assign("http:google.com");
The assign() method loads a new document.
reload
location.reload();
The reload() method is used to reload the current document.
answered Jan 28 '14 at 18:25
user2675617user2675617
20934
20934
add a comment |
add a comment |
Simply replacing the src
attribute of the iframe element was not satisfactory in my case because one would see the old content until the new page is loaded. This works better if you want to give instant visual feedback:
var url = iframeEl.src;
iframeEl.src = 'about:blank';
setTimeout(function() {
iframeEl.src = url;
}, 10);
I've just tested the same approach but without setTimeout - and it worked for me. actually, just iframe.setAttribute('src', iframe.getAttribute('src'))
– bonbonez
May 11 '16 at 15:56
add a comment |
Simply replacing the src
attribute of the iframe element was not satisfactory in my case because one would see the old content until the new page is loaded. This works better if you want to give instant visual feedback:
var url = iframeEl.src;
iframeEl.src = 'about:blank';
setTimeout(function() {
iframeEl.src = url;
}, 10);
I've just tested the same approach but without setTimeout - and it worked for me. actually, just iframe.setAttribute('src', iframe.getAttribute('src'))
– bonbonez
May 11 '16 at 15:56
add a comment |
Simply replacing the src
attribute of the iframe element was not satisfactory in my case because one would see the old content until the new page is loaded. This works better if you want to give instant visual feedback:
var url = iframeEl.src;
iframeEl.src = 'about:blank';
setTimeout(function() {
iframeEl.src = url;
}, 10);
Simply replacing the src
attribute of the iframe element was not satisfactory in my case because one would see the old content until the new page is loaded. This works better if you want to give instant visual feedback:
var url = iframeEl.src;
iframeEl.src = 'about:blank';
setTimeout(function() {
iframeEl.src = url;
}, 10);
answered Sep 23 '15 at 13:28
Patrick RudolphPatrick Rudolph
1,8701124
1,8701124
I've just tested the same approach but without setTimeout - and it worked for me. actually, just iframe.setAttribute('src', iframe.getAttribute('src'))
– bonbonez
May 11 '16 at 15:56
add a comment |
I've just tested the same approach but without setTimeout - and it worked for me. actually, just iframe.setAttribute('src', iframe.getAttribute('src'))
– bonbonez
May 11 '16 at 15:56
I've just tested the same approach but without setTimeout - and it worked for me. actually, just iframe.setAttribute('src', iframe.getAttribute('src'))
– bonbonez
May 11 '16 at 15:56
I've just tested the same approach but without setTimeout - and it worked for me. actually, just iframe.setAttribute('src', iframe.getAttribute('src'))
– bonbonez
May 11 '16 at 15:56
add a comment |
In IE8 using .Net, setting the iframe.src
for the first time is ok,
but setting the iframe.src
for the second time is not raising the page_load
of the iframed page.
To solve it i used iframe.contentDocument.location.href = "NewUrl.htm"
.
Discover it when used jQuery thickBox and tried to reopen same page in the thickbox iframe.
Then it just showed the earlier page that was opened.
you just saved my bacon with that one - awesome
– Dr. Frankenstein
May 7 '10 at 13:25
anytime yaya ..
– Shaulian
Jun 6 '10 at 20:26
add a comment |
In IE8 using .Net, setting the iframe.src
for the first time is ok,
but setting the iframe.src
for the second time is not raising the page_load
of the iframed page.
To solve it i used iframe.contentDocument.location.href = "NewUrl.htm"
.
Discover it when used jQuery thickBox and tried to reopen same page in the thickbox iframe.
Then it just showed the earlier page that was opened.
you just saved my bacon with that one - awesome
– Dr. Frankenstein
May 7 '10 at 13:25
anytime yaya ..
– Shaulian
Jun 6 '10 at 20:26
add a comment |
In IE8 using .Net, setting the iframe.src
for the first time is ok,
but setting the iframe.src
for the second time is not raising the page_load
of the iframed page.
To solve it i used iframe.contentDocument.location.href = "NewUrl.htm"
.
Discover it when used jQuery thickBox and tried to reopen same page in the thickbox iframe.
Then it just showed the earlier page that was opened.
In IE8 using .Net, setting the iframe.src
for the first time is ok,
but setting the iframe.src
for the second time is not raising the page_load
of the iframed page.
To solve it i used iframe.contentDocument.location.href = "NewUrl.htm"
.
Discover it when used jQuery thickBox and tried to reopen same page in the thickbox iframe.
Then it just showed the earlier page that was opened.
edited Oct 6 '11 at 9:55
Nikhil Ben Kuruvilla
1,61821634
1,61821634
answered Feb 1 '10 at 9:43
ShaulianShaulian
32148
32148
you just saved my bacon with that one - awesome
– Dr. Frankenstein
May 7 '10 at 13:25
anytime yaya ..
– Shaulian
Jun 6 '10 at 20:26
add a comment |
you just saved my bacon with that one - awesome
– Dr. Frankenstein
May 7 '10 at 13:25
anytime yaya ..
– Shaulian
Jun 6 '10 at 20:26
you just saved my bacon with that one - awesome
– Dr. Frankenstein
May 7 '10 at 13:25
you just saved my bacon with that one - awesome
– Dr. Frankenstein
May 7 '10 at 13:25
anytime yaya ..
– Shaulian
Jun 6 '10 at 20:26
anytime yaya ..
– Shaulian
Jun 6 '10 at 20:26
add a comment |
Use reload for IE and set src for other browsers. (reload does not work on FF)
tested on IE 7,8,9 and Firefox
if(navigator.appName == "Microsoft Internet Explorer"){
window.document.getElementById('iframeId').contentWindow.location.reload(true);
}else {
window.document.getElementById('iframeId').src = window.document.getElementById('iframeId').src;
}
This seemed to work fine on Firefox for me.
– Matt Browne
Mar 16 '12 at 18:18
add a comment |
Use reload for IE and set src for other browsers. (reload does not work on FF)
tested on IE 7,8,9 and Firefox
if(navigator.appName == "Microsoft Internet Explorer"){
window.document.getElementById('iframeId').contentWindow.location.reload(true);
}else {
window.document.getElementById('iframeId').src = window.document.getElementById('iframeId').src;
}
This seemed to work fine on Firefox for me.
– Matt Browne
Mar 16 '12 at 18:18
add a comment |
Use reload for IE and set src for other browsers. (reload does not work on FF)
tested on IE 7,8,9 and Firefox
if(navigator.appName == "Microsoft Internet Explorer"){
window.document.getElementById('iframeId').contentWindow.location.reload(true);
}else {
window.document.getElementById('iframeId').src = window.document.getElementById('iframeId').src;
}
Use reload for IE and set src for other browsers. (reload does not work on FF)
tested on IE 7,8,9 and Firefox
if(navigator.appName == "Microsoft Internet Explorer"){
window.document.getElementById('iframeId').contentWindow.location.reload(true);
}else {
window.document.getElementById('iframeId').src = window.document.getElementById('iframeId').src;
}
answered Nov 29 '11 at 1:23
yajrayajra
291
291
This seemed to work fine on Firefox for me.
– Matt Browne
Mar 16 '12 at 18:18
add a comment |
This seemed to work fine on Firefox for me.
– Matt Browne
Mar 16 '12 at 18:18
This seemed to work fine on Firefox for me.
– Matt Browne
Mar 16 '12 at 18:18
This seemed to work fine on Firefox for me.
– Matt Browne
Mar 16 '12 at 18:18
add a comment |
Have you considered appending to the url a meaningless query string parameter?
<iframe src="myBaseURL.com/something/" />
<script>
var i = document.getElementsById("iframe")[0],
src = i.src,
number = 1;
//For an update
i.src = src + "?ignoreMe=" + number;
number++;
</script>
It won't be seen & if you are aware of the parameter being safe then it should be fine.
add a comment |
Have you considered appending to the url a meaningless query string parameter?
<iframe src="myBaseURL.com/something/" />
<script>
var i = document.getElementsById("iframe")[0],
src = i.src,
number = 1;
//For an update
i.src = src + "?ignoreMe=" + number;
number++;
</script>
It won't be seen & if you are aware of the parameter being safe then it should be fine.
add a comment |
Have you considered appending to the url a meaningless query string parameter?
<iframe src="myBaseURL.com/something/" />
<script>
var i = document.getElementsById("iframe")[0],
src = i.src,
number = 1;
//For an update
i.src = src + "?ignoreMe=" + number;
number++;
</script>
It won't be seen & if you are aware of the parameter being safe then it should be fine.
Have you considered appending to the url a meaningless query string parameter?
<iframe src="myBaseURL.com/something/" />
<script>
var i = document.getElementsById("iframe")[0],
src = i.src,
number = 1;
//For an update
i.src = src + "?ignoreMe=" + number;
number++;
</script>
It won't be seen & if you are aware of the parameter being safe then it should be fine.
answered Feb 7 '14 at 22:02
user1212212user1212212
74574
74574
add a comment |
add a comment |
If you using Jquery then there is one line code.
$('#iframeID',window.parent.document).attr('src',$('#iframeID',window.parent.document).attr('src'));
and if you are working with same parent then
$('#iframeID',parent.document).attr('src',$('#iframeID',parent.document).attr('src'));
add a comment |
If you using Jquery then there is one line code.
$('#iframeID',window.parent.document).attr('src',$('#iframeID',window.parent.document).attr('src'));
and if you are working with same parent then
$('#iframeID',parent.document).attr('src',$('#iframeID',parent.document).attr('src'));
add a comment |
If you using Jquery then there is one line code.
$('#iframeID',window.parent.document).attr('src',$('#iframeID',window.parent.document).attr('src'));
and if you are working with same parent then
$('#iframeID',parent.document).attr('src',$('#iframeID',parent.document).attr('src'));
If you using Jquery then there is one line code.
$('#iframeID',window.parent.document).attr('src',$('#iframeID',window.parent.document).attr('src'));
and if you are working with same parent then
$('#iframeID',parent.document).attr('src',$('#iframeID',parent.document).attr('src'));
edited May 9 '14 at 10:32
answered May 9 '14 at 6:51
Paresh3489227Paresh3489227
689621
689621
add a comment |
add a comment |
If all of the above doesn't work for you:
window.location.reload();
This for some reason refreshed my iframe instead of the whole script. Maybe because it is placed in the frame itself, while all those getElemntById solutions work when you try to refresh a frame from another frame?
Or I don't understand this fully and talk gibberish, anyways this worked for me like a charm :)
add a comment |
If all of the above doesn't work for you:
window.location.reload();
This for some reason refreshed my iframe instead of the whole script. Maybe because it is placed in the frame itself, while all those getElemntById solutions work when you try to refresh a frame from another frame?
Or I don't understand this fully and talk gibberish, anyways this worked for me like a charm :)
add a comment |
If all of the above doesn't work for you:
window.location.reload();
This for some reason refreshed my iframe instead of the whole script. Maybe because it is placed in the frame itself, while all those getElemntById solutions work when you try to refresh a frame from another frame?
Or I don't understand this fully and talk gibberish, anyways this worked for me like a charm :)
If all of the above doesn't work for you:
window.location.reload();
This for some reason refreshed my iframe instead of the whole script. Maybe because it is placed in the frame itself, while all those getElemntById solutions work when you try to refresh a frame from another frame?
Or I don't understand this fully and talk gibberish, anyways this worked for me like a charm :)
answered Jul 23 '13 at 11:08
Marcin JaneczekMarcin Janeczek
234
234
add a comment |
add a comment |
Using self.location.reload()
will reload the iframe.
<iframe src="https://vivekkumar11432.wordpress.com/" width="300" height="300"></iframe>
<br><br>
<input type='button' value="Reload" onclick="self.location.reload();" />
add a comment |
Using self.location.reload()
will reload the iframe.
<iframe src="https://vivekkumar11432.wordpress.com/" width="300" height="300"></iframe>
<br><br>
<input type='button' value="Reload" onclick="self.location.reload();" />
add a comment |
Using self.location.reload()
will reload the iframe.
<iframe src="https://vivekkumar11432.wordpress.com/" width="300" height="300"></iframe>
<br><br>
<input type='button' value="Reload" onclick="self.location.reload();" />
Using self.location.reload()
will reload the iframe.
<iframe src="https://vivekkumar11432.wordpress.com/" width="300" height="300"></iframe>
<br><br>
<input type='button' value="Reload" onclick="self.location.reload();" />
<iframe src="https://vivekkumar11432.wordpress.com/" width="300" height="300"></iframe>
<br><br>
<input type='button' value="Reload" onclick="self.location.reload();" />
<iframe src="https://vivekkumar11432.wordpress.com/" width="300" height="300"></iframe>
<br><br>
<input type='button' value="Reload" onclick="self.location.reload();" />
edited Mar 26 '18 at 13:24
answered May 1 '17 at 8:17
Vivek KumarVivek Kumar
4502516
4502516
add a comment |
add a comment |
Now to make this work on chrome 66, try this:
const reloadIframe = (iframeId) => {
const el = document.getElementById(iframeId)
const src = el.src
el.src = ''
setTimeout(() => {
el.src = src
})
}
add a comment |
Now to make this work on chrome 66, try this:
const reloadIframe = (iframeId) => {
const el = document.getElementById(iframeId)
const src = el.src
el.src = ''
setTimeout(() => {
el.src = src
})
}
add a comment |
Now to make this work on chrome 66, try this:
const reloadIframe = (iframeId) => {
const el = document.getElementById(iframeId)
const src = el.src
el.src = ''
setTimeout(() => {
el.src = src
})
}
Now to make this work on chrome 66, try this:
const reloadIframe = (iframeId) => {
const el = document.getElementById(iframeId)
const src = el.src
el.src = ''
setTimeout(() => {
el.src = src
})
}
answered May 24 '18 at 13:57
NorthernNorthern
563413
563413
add a comment |
add a comment |
<script type="text/javascript">
top.frames['DetailFrame'].location = top.frames['DetailFrame'].location;
</script>
1
Not the choice I would use but I guess it would do. With some additional code that you could have added in.
– transilvlad
Oct 21 '12 at 13:11
add a comment |
<script type="text/javascript">
top.frames['DetailFrame'].location = top.frames['DetailFrame'].location;
</script>
1
Not the choice I would use but I guess it would do. With some additional code that you could have added in.
– transilvlad
Oct 21 '12 at 13:11
add a comment |
<script type="text/javascript">
top.frames['DetailFrame'].location = top.frames['DetailFrame'].location;
</script>
<script type="text/javascript">
top.frames['DetailFrame'].location = top.frames['DetailFrame'].location;
</script>
edited May 22 '12 at 23:54
Tharabas
3,1031825
3,1031825
answered May 22 '12 at 19:06
SidSid
11
11
1
Not the choice I would use but I guess it would do. With some additional code that you could have added in.
– transilvlad
Oct 21 '12 at 13:11
add a comment |
1
Not the choice I would use but I guess it would do. With some additional code that you could have added in.
– transilvlad
Oct 21 '12 at 13:11
1
1
Not the choice I would use but I guess it would do. With some additional code that you could have added in.
– transilvlad
Oct 21 '12 at 13:11
Not the choice I would use but I guess it would do. With some additional code that you could have added in.
– transilvlad
Oct 21 '12 at 13:11
add a comment |
If you tried all of the other suggestions, and couldn't get any of them to work (like I couldn't), here's something you can try that may be useful.
HTML
<a class="refresh-this-frame" rel="#iframe-id-0">Refresh</a>
<iframe src="" id="iframe-id-0"></iframe>
JS
$('.refresh-this-frame').click(function() {
var thisIframe = $(this).attr('rel');
var currentState = $(thisIframe).attr('src');
function removeSrc() {
$(thisIframe).attr('src', '');
}
setTimeout (removeSrc, 100);
function replaceSrc() {
$(thisIframe).attr('src', currentState);
}
setTimeout (replaceSrc, 200);
});
I initially set out to try and save some time with RWD and cross-browser testing. I wanted to create a quick page that housed a bunch of iframes, organized into groups that I would show/hide at will. Logically you'd want to be able to easily and quickly refresh any given frame.
I should note that the project I am working on currently, the one in use in this test-bed, is a one-page site with indexed locations (e.g. index.html#home). That may have had something to do with why I couldn't get any of the other solutions to refresh my particular frame.
Having said that, I know it's not the cleanest thing in the world, but it works for my purposes. Hope this helps someone. Now if only I could figure out how to keep the iframe from scrolling the parent page each time there's animation inside iframe...
EDIT:
I realized that this doesn't "refresh" the iframe like I'd hoped it would. It will reload the iframe's initial source though. Still can't figure out why I couldn't get any of the other options to work..
UPDATE:
The reason I couldn't get any of the other methods to work is because I was testing them in Chrome, and Chrome won't allow you to access an iframe's content (Explanation: Is it likely that future releases of Chrome support contentWindow/contentDocument when iFrame loads a local html file from local html file?) if it doesn't originate from the same location (so far as I understand it). Upon further testing, I can't access contentWindow in FF either.
AMENDED JS
$('.refresh-this-frame').click(function() {
var targetID = $(this).attr('rel');
var targetSrc = $(targetID).attr('src');
var cleanID = targetID.replace("#","");
var chromeTest = ( navigator.userAgent.match(/Chrome/g) ? true : false );
var FFTest = ( navigator.userAgent.match(/Firefox/g) ? true : false );
if (chromeTest == true) {
function removeSrc() {
$(targetID).attr('src', '');
}
setTimeout (removeSrc, 100);
function replaceSrc() {
$(targetID).attr('src', targetSrc);
}
setTimeout (replaceSrc, 200);
}
if (FFTest == true) {
function removeSrc() {
$(targetID).attr('src', '');
}
setTimeout (removeSrc, 100);
function replaceSrc() {
$(targetID).attr('src', targetSrc);
}
setTimeout (replaceSrc, 200);
}
if (chromeTest == false && FFTest == false) {
var targetLoc = (document.getElementById(cleanID).contentWindow.location).toString();
function removeSrc() {
$(targetID).attr('src', '');
}
setTimeout (removeSrc, 100);
function replaceSrc2() {
$(targetID).attr('src', targetLoc);
}
setTimeout (replaceSrc2, 200);
}
});
add a comment |
If you tried all of the other suggestions, and couldn't get any of them to work (like I couldn't), here's something you can try that may be useful.
HTML
<a class="refresh-this-frame" rel="#iframe-id-0">Refresh</a>
<iframe src="" id="iframe-id-0"></iframe>
JS
$('.refresh-this-frame').click(function() {
var thisIframe = $(this).attr('rel');
var currentState = $(thisIframe).attr('src');
function removeSrc() {
$(thisIframe).attr('src', '');
}
setTimeout (removeSrc, 100);
function replaceSrc() {
$(thisIframe).attr('src', currentState);
}
setTimeout (replaceSrc, 200);
});
I initially set out to try and save some time with RWD and cross-browser testing. I wanted to create a quick page that housed a bunch of iframes, organized into groups that I would show/hide at will. Logically you'd want to be able to easily and quickly refresh any given frame.
I should note that the project I am working on currently, the one in use in this test-bed, is a one-page site with indexed locations (e.g. index.html#home). That may have had something to do with why I couldn't get any of the other solutions to refresh my particular frame.
Having said that, I know it's not the cleanest thing in the world, but it works for my purposes. Hope this helps someone. Now if only I could figure out how to keep the iframe from scrolling the parent page each time there's animation inside iframe...
EDIT:
I realized that this doesn't "refresh" the iframe like I'd hoped it would. It will reload the iframe's initial source though. Still can't figure out why I couldn't get any of the other options to work..
UPDATE:
The reason I couldn't get any of the other methods to work is because I was testing them in Chrome, and Chrome won't allow you to access an iframe's content (Explanation: Is it likely that future releases of Chrome support contentWindow/contentDocument when iFrame loads a local html file from local html file?) if it doesn't originate from the same location (so far as I understand it). Upon further testing, I can't access contentWindow in FF either.
AMENDED JS
$('.refresh-this-frame').click(function() {
var targetID = $(this).attr('rel');
var targetSrc = $(targetID).attr('src');
var cleanID = targetID.replace("#","");
var chromeTest = ( navigator.userAgent.match(/Chrome/g) ? true : false );
var FFTest = ( navigator.userAgent.match(/Firefox/g) ? true : false );
if (chromeTest == true) {
function removeSrc() {
$(targetID).attr('src', '');
}
setTimeout (removeSrc, 100);
function replaceSrc() {
$(targetID).attr('src', targetSrc);
}
setTimeout (replaceSrc, 200);
}
if (FFTest == true) {
function removeSrc() {
$(targetID).attr('src', '');
}
setTimeout (removeSrc, 100);
function replaceSrc() {
$(targetID).attr('src', targetSrc);
}
setTimeout (replaceSrc, 200);
}
if (chromeTest == false && FFTest == false) {
var targetLoc = (document.getElementById(cleanID).contentWindow.location).toString();
function removeSrc() {
$(targetID).attr('src', '');
}
setTimeout (removeSrc, 100);
function replaceSrc2() {
$(targetID).attr('src', targetLoc);
}
setTimeout (replaceSrc2, 200);
}
});
add a comment |
If you tried all of the other suggestions, and couldn't get any of them to work (like I couldn't), here's something you can try that may be useful.
HTML
<a class="refresh-this-frame" rel="#iframe-id-0">Refresh</a>
<iframe src="" id="iframe-id-0"></iframe>
JS
$('.refresh-this-frame').click(function() {
var thisIframe = $(this).attr('rel');
var currentState = $(thisIframe).attr('src');
function removeSrc() {
$(thisIframe).attr('src', '');
}
setTimeout (removeSrc, 100);
function replaceSrc() {
$(thisIframe).attr('src', currentState);
}
setTimeout (replaceSrc, 200);
});
I initially set out to try and save some time with RWD and cross-browser testing. I wanted to create a quick page that housed a bunch of iframes, organized into groups that I would show/hide at will. Logically you'd want to be able to easily and quickly refresh any given frame.
I should note that the project I am working on currently, the one in use in this test-bed, is a one-page site with indexed locations (e.g. index.html#home). That may have had something to do with why I couldn't get any of the other solutions to refresh my particular frame.
Having said that, I know it's not the cleanest thing in the world, but it works for my purposes. Hope this helps someone. Now if only I could figure out how to keep the iframe from scrolling the parent page each time there's animation inside iframe...
EDIT:
I realized that this doesn't "refresh" the iframe like I'd hoped it would. It will reload the iframe's initial source though. Still can't figure out why I couldn't get any of the other options to work..
UPDATE:
The reason I couldn't get any of the other methods to work is because I was testing them in Chrome, and Chrome won't allow you to access an iframe's content (Explanation: Is it likely that future releases of Chrome support contentWindow/contentDocument when iFrame loads a local html file from local html file?) if it doesn't originate from the same location (so far as I understand it). Upon further testing, I can't access contentWindow in FF either.
AMENDED JS
$('.refresh-this-frame').click(function() {
var targetID = $(this).attr('rel');
var targetSrc = $(targetID).attr('src');
var cleanID = targetID.replace("#","");
var chromeTest = ( navigator.userAgent.match(/Chrome/g) ? true : false );
var FFTest = ( navigator.userAgent.match(/Firefox/g) ? true : false );
if (chromeTest == true) {
function removeSrc() {
$(targetID).attr('src', '');
}
setTimeout (removeSrc, 100);
function replaceSrc() {
$(targetID).attr('src', targetSrc);
}
setTimeout (replaceSrc, 200);
}
if (FFTest == true) {
function removeSrc() {
$(targetID).attr('src', '');
}
setTimeout (removeSrc, 100);
function replaceSrc() {
$(targetID).attr('src', targetSrc);
}
setTimeout (replaceSrc, 200);
}
if (chromeTest == false && FFTest == false) {
var targetLoc = (document.getElementById(cleanID).contentWindow.location).toString();
function removeSrc() {
$(targetID).attr('src', '');
}
setTimeout (removeSrc, 100);
function replaceSrc2() {
$(targetID).attr('src', targetLoc);
}
setTimeout (replaceSrc2, 200);
}
});
If you tried all of the other suggestions, and couldn't get any of them to work (like I couldn't), here's something you can try that may be useful.
HTML
<a class="refresh-this-frame" rel="#iframe-id-0">Refresh</a>
<iframe src="" id="iframe-id-0"></iframe>
JS
$('.refresh-this-frame').click(function() {
var thisIframe = $(this).attr('rel');
var currentState = $(thisIframe).attr('src');
function removeSrc() {
$(thisIframe).attr('src', '');
}
setTimeout (removeSrc, 100);
function replaceSrc() {
$(thisIframe).attr('src', currentState);
}
setTimeout (replaceSrc, 200);
});
I initially set out to try and save some time with RWD and cross-browser testing. I wanted to create a quick page that housed a bunch of iframes, organized into groups that I would show/hide at will. Logically you'd want to be able to easily and quickly refresh any given frame.
I should note that the project I am working on currently, the one in use in this test-bed, is a one-page site with indexed locations (e.g. index.html#home). That may have had something to do with why I couldn't get any of the other solutions to refresh my particular frame.
Having said that, I know it's not the cleanest thing in the world, but it works for my purposes. Hope this helps someone. Now if only I could figure out how to keep the iframe from scrolling the parent page each time there's animation inside iframe...
EDIT:
I realized that this doesn't "refresh" the iframe like I'd hoped it would. It will reload the iframe's initial source though. Still can't figure out why I couldn't get any of the other options to work..
UPDATE:
The reason I couldn't get any of the other methods to work is because I was testing them in Chrome, and Chrome won't allow you to access an iframe's content (Explanation: Is it likely that future releases of Chrome support contentWindow/contentDocument when iFrame loads a local html file from local html file?) if it doesn't originate from the same location (so far as I understand it). Upon further testing, I can't access contentWindow in FF either.
AMENDED JS
$('.refresh-this-frame').click(function() {
var targetID = $(this).attr('rel');
var targetSrc = $(targetID).attr('src');
var cleanID = targetID.replace("#","");
var chromeTest = ( navigator.userAgent.match(/Chrome/g) ? true : false );
var FFTest = ( navigator.userAgent.match(/Firefox/g) ? true : false );
if (chromeTest == true) {
function removeSrc() {
$(targetID).attr('src', '');
}
setTimeout (removeSrc, 100);
function replaceSrc() {
$(targetID).attr('src', targetSrc);
}
setTimeout (replaceSrc, 200);
}
if (FFTest == true) {
function removeSrc() {
$(targetID).attr('src', '');
}
setTimeout (removeSrc, 100);
function replaceSrc() {
$(targetID).attr('src', targetSrc);
}
setTimeout (replaceSrc, 200);
}
if (chromeTest == false && FFTest == false) {
var targetLoc = (document.getElementById(cleanID).contentWindow.location).toString();
function removeSrc() {
$(targetID).attr('src', '');
}
setTimeout (removeSrc, 100);
function replaceSrc2() {
$(targetID).attr('src', targetLoc);
}
setTimeout (replaceSrc2, 200);
}
});
edited May 23 '17 at 12:02
Community♦
11
11
answered Apr 3 '14 at 22:07
ToddTodd
5219
5219
add a comment |
add a comment |
For debugging purposes one could open the console change the execution context to the frame that he wants refreshed and do document.location.reload()
add a comment |
For debugging purposes one could open the console change the execution context to the frame that he wants refreshed and do document.location.reload()
add a comment |
For debugging purposes one could open the console change the execution context to the frame that he wants refreshed and do document.location.reload()
For debugging purposes one could open the console change the execution context to the frame that he wants refreshed and do document.location.reload()
answered Sep 13 '17 at 14:00
h3dkandih3dkandi
342315
342315
add a comment |
add a comment |
Another solution.
const frame = document.getElementById("my-iframe");
frame.parentNode.replaceChild(frame.cloneNode(), frame);
A disadvantage of that is modifies the root document DOM tree and will cause a repaint. I usedvar url = ifr.src; ifr.src = null; ifr.src = url;
– Pocketsand
Feb 27 '18 at 12:10
I think that reloading an iframe will always cause a repaint no matter of the code used.
– Vasile Alexandru Peşte
Mar 4 '18 at 21:45
add a comment |
Another solution.
const frame = document.getElementById("my-iframe");
frame.parentNode.replaceChild(frame.cloneNode(), frame);
A disadvantage of that is modifies the root document DOM tree and will cause a repaint. I usedvar url = ifr.src; ifr.src = null; ifr.src = url;
– Pocketsand
Feb 27 '18 at 12:10
I think that reloading an iframe will always cause a repaint no matter of the code used.
– Vasile Alexandru Peşte
Mar 4 '18 at 21:45
add a comment |
Another solution.
const frame = document.getElementById("my-iframe");
frame.parentNode.replaceChild(frame.cloneNode(), frame);
Another solution.
const frame = document.getElementById("my-iframe");
frame.parentNode.replaceChild(frame.cloneNode(), frame);
answered Jan 7 '18 at 17:02
Vasile Alexandru PeşteVasile Alexandru Peşte
13419
13419
A disadvantage of that is modifies the root document DOM tree and will cause a repaint. I usedvar url = ifr.src; ifr.src = null; ifr.src = url;
– Pocketsand
Feb 27 '18 at 12:10
I think that reloading an iframe will always cause a repaint no matter of the code used.
– Vasile Alexandru Peşte
Mar 4 '18 at 21:45
add a comment |
A disadvantage of that is modifies the root document DOM tree and will cause a repaint. I usedvar url = ifr.src; ifr.src = null; ifr.src = url;
– Pocketsand
Feb 27 '18 at 12:10
I think that reloading an iframe will always cause a repaint no matter of the code used.
– Vasile Alexandru Peşte
Mar 4 '18 at 21:45
A disadvantage of that is modifies the root document DOM tree and will cause a repaint. I used
var url = ifr.src; ifr.src = null; ifr.src = url;
– Pocketsand
Feb 27 '18 at 12:10
A disadvantage of that is modifies the root document DOM tree and will cause a repaint. I used
var url = ifr.src; ifr.src = null; ifr.src = url;
– Pocketsand
Feb 27 '18 at 12:10
I think that reloading an iframe will always cause a repaint no matter of the code used.
– Vasile Alexandru Peşte
Mar 4 '18 at 21:45
I think that reloading an iframe will always cause a repaint no matter of the code used.
– Vasile Alexandru Peşte
Mar 4 '18 at 21:45
add a comment |
3
Is there a reason why setting the
src
attribute to itself isn't clean? It seems to be the only solution that works across browsers and across domains– mirhagk
Sep 22 '15 at 18:21