Results 1 to 5 of 5

Thread: Seemingly simple, guess not.....

  1. #1
    Join Date
    Sep 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default Seemingly simple, guess not.....

    Looking for a way to bring a self refreshing update page to the front, not against a users will, it's a service for my users. The page works as is but I need it to be the top window when it reloads (12,15 or 30 minutes).

    Tried onload, onfocus onblur etc.. but none of them work in firefox which over 30% of my users have with the remaining bulk using IE.

    The refresh code looks like this:

    <html>
    <head>
    <title>ForexGuru UPDATE alert.</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
    <style type="text/css">

    /* Begin Styles for User's Select Refresh Rate w/counter */

    #reCounter b { /* Set Style for 'Refresh Disabled' Message */
    color:red;
    background-color:white;
    font-weight:bold;
    }
    #refreshCounter { /* Set these two styles for Select Refresh Counter Container */
    border-collapse:collapse;
    border:1px solid black;
    font-family:tahoma,verdana,arial,sans-serif;
    font-size:.9em;
    }
    #refreshCounter td {
    padding:10px;
    }
    #preCount { /* These three Styles should remain unchanged */
    visibility:hidden;
    }
    #preC, #sufC {
    display:none;
    }

    /* End Styles for User's Select Refresh Rate w/counter */

    </style>


    </head>
    <body>

    <center>


    <font face=verdana size=2><b>
    ForexGuru.co.uk
    </b></font>


    CONTENT HERE

    <script type="text/javascript">

    //Set number of days persistence for Cookie
    var pDays=30

    //NOTE: HTML allowed in Set Strings
    //Put text all on one line

    //Set String for select header:
    var selHead="Set alert update frequency:<br>"

    //Set String for Explanation of this setting to users:
    var reExp="<br>Your choice will persist for "+pDays+" Days, cookies need to be active.<br>Clearing or resetting of cookies will reset the counter.<br>"

    //Set String for Refresh Disabled:
    var reDis="Refresh Disabled"

    //Set String for counter prefix text:
    var prefixC="There are"

    //Set String for counter suffix text:
    var suffixC="seconds left until page refresh."

    /////////////////////Stop Editing Script///////////////////

    //Begin http://www.forexguru.co.uk Cookie Code:

    function createCookie(name,value,days)
    {
    if (days)
    {
    var date = new Date();
    date.setTime(date.getTime()+(days*24*60*60*1000));
    var expires = "; expires="+date.toGMTString();
    }
    else var expires = "";
    document.cookie = name+"="+value+expires+"; path=/";
    }

    function readCookie(name)
    {
    var nameEQ = name + "=";
    var ca = document.cookie.split(';');
    for(var i=0;i < ca.length;i++)
    {
    var c = ca[i];
    while (c.charAt(0)==' ') c = c.substring(1,c.length);
    if (c.indexOf(nameEQ) == 0) return c.substring(nameEQ.length,c.length);
    }
    return null;
    }

    function eraseCookie(name)
    {
    createCookie(name,"",-1);
    }

    //End http://www.forexguru.co.uk Cookie Code

    var reIt, countRe, reCounter, text1, text2, opt

    function doit(){
    if (window.location.reload)
    window.location.reload( true );
    else if (window.location.replace)
    window.location.replace(unescape(location.href))
    else
    window.location.href=unescape(location.href)
    }

    function startUp(){
    text1=document.getElementById? document.getElementById('preC').style : document.all['preC'].style
    text2=document.getElementById? document.getElementById('sufC').style : document.all['sufC'].style
    clearInterval(countRe)
    if (readCookie('resetInt')!=null){
    opt=(readCookie('resetInt')/1000).toString(10).length
    text1.display=text2.display='inline'
    reCounter=document.getElementById? document.getElementById('reCounter') : document.all['reCounter']
    reCounter.innerHTML=padTo(readCookie('resetInt')/1000)
    var opts=document.getElementById? document.getElementById('selRe').options : document.all['selRe'].options
    for (var i_tem = 0; i_tem < opts.length; i_tem++)
    if (opts[i_tem].value==readCookie('resetInt')/1000)
    opts.selectedIndex=i_tem
    countRe=setInterval("reCounter.innerHTML=padTo(parseInt(reCounter.innerHTML, 10)-1)", 1000)
    reIt=setTimeout("doit()", readCookie('resetInt'))
    }
    else
    return;
    }

    function padTo(val){
    var val=val.toString(10)
    var preCount=document.getElementById? document.getElementById('preCount') : document.all['preCount']
    preCount.innerHTML=val.length==1&&opt==3? '00' : (val.length==2&&opt==3)||(val.length==1&&opt==2)? '0' : ''
    return val
    }

    function setRe(val){
    clearTimeout(reIt)
    if (val==0){
    text1.display=text2.display='none'
    clearInterval(countRe)
    reCounter.innerHTML='<b>'+reDis+'</b>'
    eraseCookie('resetInt')
    return;
    }
    createCookie('resetInt', val*1000, pDays)
    startUp();
    }

    onload=startUp;

    with (document){
    write('<table id="refreshCounter"><tr><td><span>'+selHead+'</span>')
    write('<select id="selRe" onchange="setRe(options[selectedIndex].value)">')
    write('<option value="0" selected>No Refresh</option>')
    write('<option value="10">12 minutes</option>')
    write('<option value="1440">24 minutes</option>')
    write('<option value="1800">30 minutes</option>')
    write('</select>')
    write('<span>'+reExp+'<span id="preC">'+prefixC+' </span><span id="preCount"></span><span id="reCounter"><b>'+reDis+'</b></span><span id="sufC"> '+suffixC+'</span></span>')
    write('</td></tr></table>')
    }

    </script>

    </center>

    </body>
    </html>

    So I just need a clever somebody who knows how to bring it to the front when it reloads. Alternatively to play a sound when it reloads IF I set a value to 1 and not play a sound if I set a value to 0. The user should be able to turn this feature off if they wish which will be stored in a cookie.

    Anybody know what I'm on about ? lol

    TIA Darren

  2. #2
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    Code:
    <script type="text/javascript">
      onload = focus;
    </script>
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

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

    Default

    Thanks Twey, tried that both in the head and in the body but it still doesn't work in FF, it refreshes still but doesn't come to the front when another window has focus.

    I think I may just have to go with an audio alert.

  4. #4
    Join Date
    Jun 2005
    Location
    英国
    Posts
    11,876
    Thanks
    1
    Thanked 180 Times in 172 Posts
    Blog Entries
    2

    Default

    It's probably a feature. The audio alert might be an idea, or you could flash the titlebar for a bit:
    Code:
    onload = (function() {
      var flashes = 0,
        alertmsg = '*** ALERT ***',
        title = document.title,
        s = function() {
          if(document.title === title)
            document.title = alertmsg;
          else
            document.title = title;
    
          if(++flashes < 10)
            setTimeout(s, 300);
          else
            document.title = title;
        };
    
        return s;
    })();
    Twey | I understand English | 日本語が分かります | mi jimpe fi le jbobau | mi esperanton komprenas | je comprends français | entiendo español | tôi ít hiểu tiếng Việt | ich verstehe ein bisschen Deutsch | beware XHTML | common coding mistakes | tutorials | various stuff | argh PHP!

  5. #5
    Join Date
    Sep 2007
    Posts
    3
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Default

    that works well. Thanks Twey.

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
  •