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

    Problema compatibilita javascript/IE

    ragazzi ho un problema con questo codice:

    <!--
    img = new Array()
    ran = Math.floor(8 * Math.random());
    img[0] = 'img/testata1.png" width="" height="" border=""';
    img[1] = 'img/testata2.png" width="" height="" border=""';
    img[2] = 'img/testata3.png" width="" height="" border=""';
    img[3] = 'img/testata4.png" width="" height="" border=""';
    img[4] = 'img/testata5.png" width="" height="" border=""';
    img[5] = 'img/testata6.png" width="" height="" border=""';
    img[6] = 'img/testata7.png" width="" height="" border=""';
    img[7] = 'img/testata8.png" width="" height="" border=""';
    document.write("<img src=\""+img[ran]+"\">");
    // -->

    Come da facile lettura capirete che serve per randommizzare delle immagini.
    Ma IE non me lo fa funzionare!
    Se qualcuno saprebbe suggerirmi come fare ne sarei grato!!

  2. #2
    Utente di HTML.it L'avatar di willybit
    Registrato dal
    May 2001
    Messaggi
    4,367
    Ciao lordmaron,

    quello script così da solo non ha problemi con IE
    potrebbe esserci qualche altro errore nella pagina.

  3. #3
    Prova questo:
    Codice PHP:
    <html>
    <
    head><title>Using more DOM</title>
    <
    script type="text/javascript">
    var 
    pimg = new Array('uno0.gif','uno1.gif','uno2.gif');
    function 
    changeImage(target)
    {
        var 
    ran Math.floor(pimg.length Math.random());
        var 
    newsImg=document.createElement('img');
        
    newsImg.setAttribute("src"pimg[ran]);
        
    target.appendChild(newsImg);
    }
    window.onload= function()
    {
    var 
    targetdocument.getElementById('boxImg');
    changeImage(target);
    }
    </script>
    </head>
    <body>
    <div id="boxImg"></div>
    </body>
    </html> 



    PS.
    Benvenuto nel forum
    Without faith, nothing is possible. With it, nothing is impossible
    http://ilwebdifabio.it

  4. #4
    Originariamente inviato da whisher
    Prova questo:
    Codice PHP:
    <html>
    <
    head><title>Using more DOM</title>
    <
    script type="text/javascript">
    var 
    pimg = new Array('uno0.gif','uno1.gif','uno2.gif');
    function 
    changeImage(target)
    {
        var 
    ran Math.floor(pimg.length Math.random());
        var 
    newsImg=document.createElement('img');
        
    newsImg.setAttribute("src"pimg[ran]);
        
    target.appendChild(newsImg);
    }
    window.onload= function()
    {
    var 
    targetdocument.getElementById('boxImg');
    changeImage(target);
    }
    </script>
    </head>
    <body>
    <div id="boxImg"></div>
    </body>
    </html> 



    PS.
    Benvenuto nel forum
    grazie provo subito!

  5. #5
    Funziona perfettamente lo script grazie mille!!

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.