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

    Problema con random quotes

    Ho un problema con uno script che crea le cosiddette "random quotes". Lo riporto:

    codice:
    <SCRIPT type="text/JavaScript"> 
    	<!-- Distributed by http://www.hypergurl.com 
    	Begin 
    	function getMessage() 
    	{	var ar = new Array(20) ;
    		ar[0] = "Buy a Pentium 586/90 so you can reboot faster." ;
    		ar[1] = "2 + 2 = 5 for extremely large values of 2." ;
    		ar[2] = "Anything that can go wrong will go wrong." ;
    		ar[3] = "Computers make very fast, very accurate mistakes." ;
    		ar[4] = "My software never has bugs. It just develops random features." ;
    		ar[5] = "If anything simply cannot go wrong, it will anyway." ;
    		ar[6] = "Best file compression around: "DEL *.*" = 100% compression" ;
    		ar[7] = "The Definition of an Upgrade: Take old bugs out, put new ones in." ;
    		ar[8] = "If everything seems to be going well, you have obviously overlooked something." ;
    		ar[9] = "BREAKFAST.COM Halted...Cereal Port Not Responding" ;
    		ar[10] = "BUFFERS=20 FILES=15 2nd down, 4th quarter, 5 yards to go!" ;
    		ar[11] = "It is impossible to make anything foolproof because fools are so ingenious." ;
    		ar[12] = "Bad command. Bad, bad command! Sit! Stay! Staaay..." ;
    		ar[13] = "Every solution breeds new problems." ;
    		ar[14] = "As a computer, I find your faith in technology amusing." ;
    		ar[15] = "Two wrongs are only the beginning." ;
    		ar[16] = "Shell to DOS... Come in DOS, do you copy? Shell to DOS..." ;
    		ar[17] = "All computers wait at the same speed." ;
    		ar[18] = "DEFINITION: Computer - A device designed to speed and automate errors." ;
    		ar[19] = "Success always occurs in private, and failure in full view." ;
    		var now = new Date(); 
    		var sec = now.getSeconds(); 
    		document.write("" + ar[sec % 20] + ""); 
    	} 
    	End 
    // -->
    </SCRIPT>
    Originariamente, al posto dell'ultima document.write c'era un comando alert, e la funzione veniva richiamata sull'onClick di un pulsante. Io invece vorrei inserirla nell'intestazione di un forum: ho quindi inserito questo codice dove voglio che la frase appaia:

    codice:
    <table class="tableborder" width=100% cellspacing=0 cellpadding=0><tr><td class=maintitle>Quote of the Day</td></tr><tr>
    <td class=row2 style="padding: 10px;">
    		
    <script type="text/Javascript">
    <!--
    getMessage();
    //-->
    </script>
    </td></tr></table>
    Il problema è che testandola su un'altra pagina localmente lo script funziona così com'è, invece nel forum in questione la citazione non appare per nulla. Viene visualizzato semplicemente il testo che circonda i tag script, come se non venisse restituito niente.

    Sapete aiutarmi? Lo script dovrebbe essere inserito in uno dei template dell'IPB, che so che permette l'inserimento di JS per la semplice ragione che ce ne sono altri funzionanti.

  2. #2
    prova con queste modifiche:

    codice:
    <SCRIPT type="text/JavaScript"> 
    	<!-- Distributed by http://www.hypergurl.com 
    	function getMessage() 
    	{	var ar = new Array(20) ;
    		ar[0] = "Buy a Pentium 586/90 so you can reboot faster." ;
    		ar[1] = "2 + 2 = 5 for extremely large values of 2." ;
    		ar[2] = "Anything that can go wrong will go wrong." ;
    		ar[3] = "Computers make very fast, very accurate mistakes." ;
    		ar[4] = "My software never has bugs. It just develops random features." ;
    		ar[5] = "If anything simply cannot go wrong, it will anyway." ;
    		ar[6] = "Best file compression around: "DEL *.*" = 100% compression" ;
    		ar[7] = "The Definition of an Upgrade: Take old bugs out, put new ones in." ;
    		ar[8] = "If everything seems to be going well, you have obviously overlooked something." ;
    		ar[9] = "BREAKFAST.COM Halted...Cereal Port Not Responding" ;
    		ar[10] = "BUFFERS=20 FILES=15 2nd down, 4th quarter, 5 yards to go!" ;
    		ar[11] = "It is impossible to make anything foolproof because fools are so ingenious." ;
    		ar[12] = "Bad command. Bad, bad command! Sit! Stay! Staaay..." ;
    		ar[13] = "Every solution breeds new problems." ;
    		ar[14] = "As a computer, I find your faith in technology amusing." ;
    		ar[15] = "Two wrongs are only the beginning." ;
    		ar[16] = "Shell to DOS... Come in DOS, do you copy? Shell to DOS..." ;
    		ar[17] = "All computers wait at the same speed." ;
    		ar[18] = "DEFINITION: Computer - A device designed to speed and automate errors." ;
    		ar[19] = "Success always occurs in private, and failure in full view." ;
    		var now = new Date(); 
    		var sec = now.getSeconds(); 
    		document.getElementById('livello').innerHTML="" + ar[sec % 20] + ""; 
    	} 
    // -->
    </SCRIPT>
    da usare cosi':

    codice:
    <body onload="getMessage();">
    e

    codice:
    <table class="tableborder" width=100% cellspacing=0 cellpadding=0><tr><td class=maintitle>Quote of the Day</td></tr><tr>
    <td class=row2 style="padding: 10px;">
    <div id="livello"></div>
    </td></tr></table>
    ciao

  3. #3
    Temo che ci sia un problema: non ho accesso al tag body della pagina. Si tratta di un elenco di template modificabili che vengono inserit all'interno di una pagina, al cui codice non ho accesso. Come posso altrimenti richiamare la funzione?

  4. #4
    Originariamente inviato da The Raven
    Temo che ci sia un problema: non ho accesso al tag body della pagina. Si tratta di un elenco di template modificabili che vengono inserit all'interno di una pagina, al cui codice non ho accesso. Come posso altrimenti richiamare la funzione?
    prova cosi':

    codice:
    <table class="tableborder" width=100% cellspacing=0 cellpadding=0><tr><td class=maintitle>Quote of the Day</td></tr><tr>
    <td class=row2 style="padding: 10px;">
    <div id="livello"></div>
    <script language="JavaScript">getMessage();</script>
    </td></tr></table>
    ciao

  5. #5
    Tutto molto bello, però purtroppo ancora non funziona. La pagina è questa: http://caproject.forumer.com. Guardando il codice, lo script c'è, sembra scritto correttamente e chiamato correttamente, eppure non funziona. Se non ricordo male, JS, essendo lato client, può essere inserito a valle del PHP (in effetti qua la pagina PHP inserisce i template, all'interno del quale ci sono i JS), quindi per il solo fatto che sia presente nel sorgente visualizzabile dal browser dovrebbe essere eseguito, giusto? Eppure non va

  6. #6
    come mai getMessage la definisci nel body?
    definiscila a livello di head e vedrai che funzionera' tutto.

  7. #7
    Non riesco più a capire niente. Con una certa forzatura sono riuscito ad inserire lo script in cui definisco la funzione nella head della pagina. Ora il codice che viene creato sembrerebbe perfetto! Ma non funziona.

    Allora provo a copiarlo e testarlo con il "Try it" del W3C, e non funziona (mentre prima funzionava). Ok, avrò sbagliato copiando. Riprendo la mia versione originale (quella che in locale funzionava), la incollo nel TryIt e funziona. Apporto le modifiche che mi hai indicato e funziona. Copio nel forum e non funziona.

    Ora ho creato una pagina con solo quello raggiungibile a questo indirizzo, e, accidenti!, funziona. Prendo uguale uguale il codice, lo sbatto nel forum e non funziona! Grrrr!

    Potete dirmi se anche a voi la pagina con solo lo script funziona? Non si vedrà granché, perché non c'è il CSS, però l'HTML è quello! Aiuto...

  8. #8
    si', funziona perfettamente.

  9. #9
    Ok, grazie. Evidentemente c'è qualcos'altro che non so. Magari forumer.com o l'IPB stessa disabilitano il document.write nei JS. Purtroppo, non potendo intervenire sul codice PHP, non ho nessun'altra soluzione.

    Grazie per aver perso il tuo tempo con me

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.