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 05-12-2011, 04:57 PM   PM User | #1
MichaelHGoebel
New to the CF scene

 
Join Date: May 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
MichaelHGoebel is an unknown quantity at this point
How to show iframe scrollbars only on mouseover ?

I have an iFrame on which I wish to display scrollbars ONLY when the mouse is over the iFrame AND the source of the iFrame is larger than the iFrame can display

I am using the following code for the iFrame but believe that I need to add some script to make it work:

Code:
<iframe src="http://www.mhgoebel.com" frameborder="0" id="frame" width="320" height="356" scrolling="no">
onmouseover="setScrolling('auto')" onmouseout="setScrolling('no')"
</iframe>
MichaelHGoebel is offline   Reply With Quote
Old 05-13-2011, 03:03 PM   PM User | #2
harbingerOTV
Senior Coder

 
Join Date: Jan 2005
Location: Memphis, TN
Posts: 1,765
Thanks: 8
Thanked 123 Times in 121 Posts
harbingerOTV will become famous soon enough
Code:
<style type="text/css">
.scroll { overflow: auto; }
.noscroll { overflow: hidden; }
</style>
<iframe src="http://www.mhgoebel.com" frameborder="0" id="frame" width="320" height="356" onmouseover="this.className='scroll'" onmouseout="this.className='noscroll'" class="noscroll">
</iframe>
__________________
Stop making things so hard on yourself.
i is tugbucket :: help raise tugburg :: Whitehaven Kiwanis
harbingerOTV is offline   Reply With Quote
Old 07-12-2012, 06:19 AM   PM User | #3
MichaelHGoebel
New to the CF scene

 
Join Date: May 2011
Posts: 3
Thanks: 0
Thanked 0 Times in 0 Posts
MichaelHGoebel is an unknown quantity at this point
Thankyou

Thankyou so much :-)
MichaelHGoebel is offline   Reply With Quote
Old 07-12-2012, 08:15 AM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by harbingerOTV View Post
Code:
<style type="text/css">
.scroll { overflow: auto; }
.noscroll { overflow: hidden; }
</style>
<iframe src="http://www.mhgoebel.com" frameborder="0" id="frame" width="320" height="356" onmouseover="this.className='scroll'" onmouseout="this.className='noscroll'" class="noscroll">
</iframe>
Does not work in IE9.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Old 07-12-2012, 01:41 PM   PM User | #5
Calvert Tripesi
New Coder

 
Join Date: Jan 2011
Posts: 51
Thanks: 0
Thanked 9 Times in 9 Posts
Calvert Tripesi is an unknown quantity at this point
Quote:
Originally Posted by MichaelHGoebel View Post
I have an iFrame on which I wish to display scrollbars ONLY when the mouse is over the iFrame AND the source of the iFrame is larger than the iFrame can display
IE doesn't seem to style overflow for iframes; perhaps for security reasons.
This works for same-domain iframes. Don't style overflow:hidden using CSS.
Code:
<iframe id='myIframe' src='iframesource.htm' ></iframe>

<script type='text/javascript'>

(function( id )
{
  function noBars( elem, action )
  {
    try
    {   
      elem.contentWindow.document.body.style.overflow = ( action ? 'hidden' : 'auto' );  
    }
    catch( e ){}
  }

  var ifr = document.getElementById( id );

  ifr.onload = function(){ noBars( ifr, true ); };

  ifr.onmouseover = function(){ noBars( ifr, false ); }

  ifr.onmouseout  = function(){ noBars( ifr, true ); }

})( "myIframe" ); 

</script>
Calvert Tripesi is offline   Reply With Quote
Old 07-12-2012, 02:31 PM   PM User | #6
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,033
Thanks: 197
Thanked 2,410 Times in 2,388 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by Calvert Tripesi View Post
IE doesn't seem to style overflow for iframes; perhaps for security reasons.
This works for same-domain iframes. Don't style overflow:hidden using CSS.
But only for same-domain iframes.
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Reply

Bookmarks

Tags
iframe, onmouseover, scrollbars

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 02:33 AM.


Advertisement
Log in to turn off these ads.