Results 1 to 8 of 8

Thread: Iframe scrollbar color script & new pages

  1. #1
    Join Date
    Nov 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Iframe scrollbar color script & new pages

    I'm using this script to color the scrollbars of an iframe which contains a .txt file:

    Code:
    <script language="JScript">
    <!--
    window.onload = ifr;
    function ifr()
    {
    	if (!document.fireEvent) return;
    	var a = document.frames['miframe'].document.body;
    	a.style.scrollbarArrowColor='white';
    	a.style.scrollbarBaseColor='black';
    	a.style.scrollbarDarkShadowColor='#3F3F3F';
    	a.style.scrollbarTrackColor='black';
    	a.style.scrollbarFaceColor='black';
    	a.style.scrollbarShadowColor='#3F3F3F';
    	a.style.scrollbarHighlightColor='#3F3F3F';
    	a.style.scrollbar3dLightColor='black';
    }
    //-->
    </script>
    It works as expected when the page loads but if a link is used to open a different .txt file in the iframe it reverts to the default scrollbar colors. Is it possible to somehow combine a call to the script with the link that's targeted to the iframe - or perhaps there's some other way to do it..?

  2. #2
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Let's say you have a link:

    Code:
    <a href="some.txt" target="miframe">Some Text</a>
    You could:

    Code:
    <a href="some.txt" target="miframe" onmouseup="ifr();">Some Text</a>
    But that might have problems if the text file doesn't load fast enough into the iframe. It might work fine locally, but probably not on a slow live connection.

    Here's something that would probably work out though:

    Code:
    <script language="JScript">
    <!--
    window.onload = function(){
    ifr();
    if (window.attachEvent)
    document.getElementsByName('miframe')[0].attachEvent('onload', ifr);
    }
    var ifr = function()
    {
    	if (!document.fireEvent) return;
    	var a = document.frames['miframe'].document.body;
    	a.style.scrollbarArrowColor='white';
    	a.style.scrollbarBaseColor='black';
    	a.style.scrollbarDarkShadowColor='#3F3F3F';
    	a.style.scrollbarTrackColor='black';
    	a.style.scrollbarFaceColor='black';
    	a.style.scrollbarShadowColor='#3F3F3F';
    	a.style.scrollbarHighlightColor='#3F3F3F';
    	a.style.scrollbar3dLightColor='black';
    }
    //-->
    </script>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  3. #3
    Join Date
    Nov 2005
    Posts
    12
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Perfect, thanks a lot, John.

  4. #4
    Join Date
    Sep 2007
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default adding a 2nd iframe

    how would you make Johns script work if you have 2 iframes on the page

    Quote Originally Posted by jscheuer1 View Post
    <script language="JScript">
    <!--
    window.onload = function(){
    ifr();
    if (window.attachEvent)
    document.getElementsByName('miframe')[0].attachEvent('onload', ifr);
    }
    var ifr = function()
    {
    if (!document.fireEvent) return;
    var a = document.frames['miframe'].document.body;
    a.style.scrollbarArrowColor='white';
    a.style.scrollbarBaseColor='black';
    a.style.scrollbarDarkShadowColor='#3F3F3F';
    a.style.scrollbarTrackColor='black';
    a.style.scrollbarFaceColor='black';
    a.style.scrollbarShadowColor='#3F3F3F';
    a.style.scrollbarHighlightColor='#3F3F3F';
    a.style.scrollbar3dLightColor='black';
    }
    //-->
    </script>[/CODE]

  5. #5
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Quote Originally Posted by big-dog1965 View Post
    how would you make Johns script work if you have 2 iframes on the page
    Well, that script actually had a few problems with it, but would still work. Here is a cleaned up version that should work out with two iframes (untested):

    Code:
    <script type="text/javascript">
    
    window.onload = function(){
    if (!window.attachEvent)
    return;
    ifr();
    document.getElementsByName('miframe')[0].attachEvent('onload', ifr);
    document.getElementsByName('mi_other_frame')[0].attachEvent('onload', ifr);
    }
    var ifr = function()
    {
    	if (!document.fireEvent)
    	return;
    	var a = {
    	a:document.frames['miframe'].document.body,
    	b:document.frames['mi_other_frame'].document.body
    	};
    	for (var i in a){
    	a[i].style.scrollbarArrowColor='white';
    	a[i].style.scrollbarBaseColor='black';
    	a[i].style.scrollbarDarkShadowColor='#3F3F3F';
    	a[i].style.scrollbarTrackColor='black';
    	a[i].style.scrollbarFaceColor='black';
    	a[i].style.scrollbarShadowColor='#3F3F3F';
    	a[i].style.scrollbarHighlightColor='#3F3F3F';
    	a[i].style.scrollbar3dLightColor='black';
    	}
    }
    
    </script>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  6. #6
    Join Date
    Sep 2007
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Thanks it seems to work just fine

  7. #7
    Join Date
    Mar 2005
    Location
    SE PA USA
    Posts
    30,495
    Thanks
    82
    Thanked 3,449 Times in 3,410 Posts
    Blog Entries
    12

    Default

    Well, there still is a minor problem, documents in an iframe cannot have a DOCTYPE which triggers compliance mode. With this version, that problem is taken care of, and I cleaned things up a bit more code wise:

    Code:
    <script type="text/javascript">
    
    window.onload = function(){
    if (!window.attachEvent||!document.fireEvent)
    return;
    ifr();
    var iframeElements = {
    a:document.getElementsByName('miframe')[0],
    b:document.getElementsByName('mi_other_frame')[0]
    };
    for (var i in iframeElements)
    iframeElements[i].attachEvent('onload', ifr);
    }
    var ifr = function(){
    var iecompattest = function(docObj){
    return docObj.compatMode && docObj.compatMode!="BackCompat"? docObj.body.parentNode : docObj.body;
    }
    	var iframeDocs = {
    	a:iecompattest(document.frames['miframe'].document),
    	b:iecompattest(document.frames['mi_other_frame'].document)
    	};
    	for (var i in iframeDocs){
    		with (iframeDocs[i].style){
    			scrollbarArrowColor='white';
    			scrollbarBaseColor='black';
    			scrollbarDarkShadowColor='#3F3F3F';
    			scrollbarTrackColor='black';
    			scrollbarFaceColor='black';
    			scrollbarShadowColor='#3F3F3F';
    			scrollbarHighlightColor='#3F3F3F';
    			scrollbar3dLightColor='black';
    		}
    	}
    }
    
    </script>
    - John
    ________________________

    Show Additional Thanks: International Rescue Committee - Donate or: The Ocean Conservancy - Donate or: PayPal - Donate

  8. #8
    Join Date
    Sep 2007
    Posts
    83
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    Ok that works to
    THANKS
    Checkout my post about a photo gallery I tried it from the site and dont work.

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •