Visualizzazione dei risultati da 1 a 3 su 3
  1. #1

    Problema tra Javascript e Firefox

    Salve a tutti. Premetto che ho visto che c'è già una discussione aperta in questi giorni, ma, visto che il problema non è ancora stato risolto, ho preferito aprire una nuova discussione per non creare maggiore confusione.
    Utilizzo una barra di attesa nella prima pagina del mio sito che in IE appare tranquillamente, mentre in Firefox/Safari non appare. Penso che ci sia qualche errore nello script della barra, anche perchè esegue senza nessun tipo di problema il redirect. Stessa cosa succede anche con uno script per il menu: con IE tutto bene, con Firefox appaiono più scritte una sopra l'altra.

    Questo è Javascript (ho messo anche CSS per completezza) della barra di attesa.
    codice:
    body {background-color: #FFC242;}
    #bar, #barbackground{
    position:absolute;
    left:0;
    top:0;
    background-color: #FF9F4F;
    }
    
    #barbackground{
    background-color: #D3D3D3;
    }
    
    -->
    </style>
    
    
    <script language="JavaScript1.2" type="text/javascript">
    <!--
    var duration=5;
    
    var message = "";
    
    var font_size = 3;
    
    var font_face = "verdana";
    
    var NS6redirection = "index0.html";
    
    var bar_width = 200;
    
    var bar_height = 15;
    
    var centered = (screen.width) ? (screen.width-bar_width)/2 : 0;
    function postaction(){
    window.location="index0.html"
    }
    
    var clipright=0
    var widthIE=0
    var widthNS=0
    
    function initializebar(){
    if (document.all){
    baranchor.style.visibility="visible"
    widthIE=bar.style.pixelWidth
    startIE=setInterval("increaseIE()",50)
    }
    if (document.layers){
    widthNS=document.baranchorNS.document.barbackgroundNS.clip.width
    document.baranchorNS.document.barNS.clip.right=0
    document.baranchorNS.visibility="show"
    
    startNS=setInterval("increaseNS()",50)
    }
    }
    
    function increaseIE(){
    bar.style.clip="rect(0 "+clipright+" auto 0)"
    window.status="Attendere..."
    if (clipright<widthIE)
    clipright=clipright+(widthIE/(duration*20))
    else{
    window.status=''
    clearInterval(startIE)
    postaction()
    }
    }
    
    function increaseNS(){
    if (clipright<202){
    window.status="Attendere..."
    document.baranchorNS.document.barNS.clip.right=clipright
    clipright=clipright+(widthNS/(duration*20))
    }
    else{
    window.status=''
    clearInterval(startNS)
    postaction()
    }
    }
    window.onload=initializebar
    E questi Javascript e CSS del menu.
    codice:
    <script type="text/javascript">
    window.onload=function(){
    if(document.getElementsByTagName && document.getElementById){
        document.getElementById("menu").className="jsenable";
        BuildList();
        }
    }
    
    function BuildList(){
    var hs=document.getElementById("menu").getElementsByTagName("h3");
    for(var i=0;i<hs.length;i++){
        hs[i].onclick=function(){
            this.parentNode.className=(this.parentNode.className=="show") ? "hide" : "show";
            }
        }
    } 
    </script>
    
    <style type="text/css">
    div#menu{width:100%;background: #FECC2B;
        border: 1px solid #FFF; font: 14px Arial, Helvetica, sans-serif}
    div#menu h3{font-size: 100%;margin: 0;
        border-top: 1px solid #FFF;color: #000;background-color: #FECC2B}
    div#menu ul,div#menu li{margin: 0;padding: 0;list-style-type: none}
    div#menu ol,div#menu li{margin: 0;padding: 0;list-style-type: none; background-color: #FEB22B;}
    div#menu li{border-top: 1px solid #FFF;font-weight: bold;}
    div#menu a{display: block;height: 18px;line-height: 18px;
        border-top: 1px solid #FFF;background-color: #FECC2B;color: #000;
        text-decoration: none;font-weight: bold}
    div#menu ul ul a{color: #333; background-color: #FEB22B;font-weight: bold} 
    
    div.jsenable h3{cursor: pointer}
    div.jsenable ul ul{display:none}
    div#menu li.hide ul{display:none}
    div#menu li.show ul{display:block}
    div#menu li.show h3{background-color: #FF0} 
    
    </style>
    Potete aiutarmi? Grazie anticipatamente.

  2. #2
    Allora, ecco le cose che, a mio avviso, non sono corrette:

    Riga 16 del primo script:
    screen.width di questo non sono sicuro, ma credo che non vada per tutti i browser

    RIga 18 del primo script:
    window.location="index0.html" non è corretto, dovrebbe essere window.location.href="index0.html"

    Riga 26 e riga 31 del primo script:
    Credo che sia qui il tuo problema: qui fai il controllo per vedere se il browser è IE (if (document.all){) oppure Netscape (if (document.layers){) ma nessuno di queste proprietà è usata in FIreFOx

    In conclusione posso dire che il tuo script va bene per IE e per Netscape, ma non per FireFox, devi aggiungere un controllo, modificando gli altri:
    Codice PHP:
    var clipright=0
    var widthIE=0
    var widthNS=0
    var widthFF 0;

    if (
    document.all){
    baranchor.style.visibility="visible"
    widthIE=bar.style.pixelWidth
    startIE
    =setInterval("increaseIE()",50)
    } else
    if (
    document.layers){
    widthNS=document.baranchorNS.document.barbackgroundNS.clip.width
    document
    .baranchorNS.document.barNS.clip.right=0
    document
    .baranchorNS.visibility="show"

    startNS=setInterval("increaseNS()",50)
    }else 
    if(
    document.getElementById)
    {
    //Spero di aver capito giusto pensando che baranchor sia un id
    var baranchor document.getElementById('baranchor');
    baranchor.style.visibility="visible";
    bar document.getElementById('bar');
    widthFF=parseInt(bar.style.width);
    startFF=setInterval("increaseFF()",50)

    creando un metodo increaseFF del tipo:

    Codice PHP:
    function increaseFF(){

    bar.style.clip="rect(0 "+clipright+" auto 0)";
    window.status="Attendere...";
    if (
    clipright<widthFF)
    clipright=clipright+(widthFF/(duration*20))
    else{
    window.status=''
    clearInterval(startFF)
    postaction()
    }

    Prova e vedi se funziona.

  3. #3
    Perfetto! La barra funziona!

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2025 vBulletin Solutions, Inc. All rights reserved.