Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 09-13-2011, 10:32 PM   PM User | #1
eabigelow
New Coder

 
Join Date: Aug 2011
Posts: 33
Thanks: 1
Thanked 0 Times in 0 Posts
eabigelow is an unknown quantity at this point
Just need a little extra to make this iframe refresh just once...

Hi--

I have found a neat trick to refresh an iframe in an html page, but I just need one little twist to make it work just right. I would like to make the iframe content refresh just once, not matter how many times the link is clicked...

Right now, I have this in the head:
Quote:
<script type="text/javascript">
function refreshIframe(el) {
var f = document.getElementById(el)
var rsrc = f.src
f.src="about:blank"
f.src=rsrc
}
</script>
And this is the link which, when clicked, refreshes the iframe every time it is clicked:
Quote:
<a href="#page_7c" onclick="refreshIframe('test'); return false">
"test" is the id of the iframe.

I am sure how to do this is really simple, but it escapes me... Many thanks!
eabigelow is offline   Reply With Quote
Old 09-13-2011, 10:38 PM   PM User | #2
xelawho
Senior Coder

 
xelawho's Avatar
 
Join Date: Nov 2010
Posts: 2,437
Thanks: 52
Thanked 454 Times in 452 Posts
xelawho will become famous soon enoughxelawho will become famous soon enough
here's a cheap and nasty way to do it...

Code:
var a=0;
function refreshIframe(el) {
if(a==0){
var f = document.getElementById(el)
var rsrc = f.src
f.src="about:blank"
f.src=rsrc
}
a=1;
}
xelawho is offline   Reply With Quote
Old 09-14-2011, 01:02 AM   PM User | #3
eabigelow
New Coder

 
Join Date: Aug 2011
Posts: 33
Thanks: 1
Thanked 0 Times in 0 Posts
eabigelow is an unknown quantity at this point
Works like a charm. Many thanks!!!!
eabigelow is offline   Reply With Quote
Old 09-14-2011, 01:51 AM   PM User | #4
Logic Ali
Regular Coder

 
Logic Ali's Avatar
 
Join Date: Sep 2010
Location: London
Posts: 961
Thanks: 0
Thanked 198 Times in 193 Posts
Logic Ali will become famous soon enoughLogic Ali will become famous soon enough
Self-cancelling handler:
Code:
<a href="#page_7c" onclick="refreshIframe('test'); this.onclick = function(){ return false; }; return false">
Logic Ali is offline   Reply With Quote
Old 09-14-2011, 02:09 AM   PM User | #5
eabigelow
New Coder

 
Join Date: Aug 2011
Posts: 33
Thanks: 1
Thanked 0 Times in 0 Posts
eabigelow is an unknown quantity at this point
This also does the trick. Thanks!
eabigelow is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 11:16 PM.


Advertisement
Log in to turn off these ads.