Joomla.it Forum

Joomla! 1.5.x (versione con supporto terminato) => Joomla! 1.5 => I Template di Joomla 1.5.x => : webskip 28 Sep 2010, 21:07:33

: Come inserire uno javascript nell'index del template
: webskip 28 Sep 2010, 21:07:33
Ho un problema con cui sto incornando da ore.
Ho uno file .js (inner.js) che per far funzionare una chat deve essere lanciano non nel <head>, ma nel <body>.
Ho provato a farlo vedere nell'<head> con questo comando
<?php
$document = &JFactory::getDocument();
$document->addScript( '/media/system/js/inner.js' );
?>
e quando lancio la home page e vedo il sorgente c'è nell'<head> tra tutti i richiami degli script in questo modo:
<script type="text/javascript" src="/media/system/js/inner.js"></script>
Il problema è che non deve stare nell'<head>, ma nel <body>. C'è un comando per richiamare la funzione dell'<head> nel <body> ???
Oppure cìè qualche altro sistema per farlo lavorare nel <body>?
Grazie 1000 a tutti
: Re:Come inserire uno javascript nell'index del template
: conti1 28 Sep 2010, 22:54:42
ciao
hai provato ad inserire il richiamo dopo il body?
oppure mettilo direttamente nel  php
:
<script type="text/javascript">
qui il tuo js
</script>
: Re:Come inserire uno javascript nell'index del template
: webskip 29 Sep 2010, 09:35:59
Lo script è questo:

:
<script type="text/javascript">
/* Settings you might want to define */
var waittime=800;

/* Internal Variables & Stuff */
chatmsg.focus()
document.getElementById("chatwindow").innerHTML = "loading...";

var xmlhttp = false;
var xmlhttp2 = false;


/* Request for Reading the Chat Content */
function ajax_read(url) {
if(window.XMLHttpRequest){
xmlhttp=new XMLHttpRequest();
if(xmlhttp.overrideMimeType){
xmlhttp.overrideMimeType('text/xml');
}
} else if(window.ActiveXObject){
try{
xmlhttp=new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try{
xmlhttp=new ActiveXObject("Microsoft.XMLHTTP");
} catch(e){
}
}
}

if(!xmlhttp) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}

xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState==4) {
document.getElementById("chatwindow").innerHTML = xmlhttp.responseText;

zeit = new Date();
ms = (zeit.getHours() * 24 * 60 * 1000) + (zeit.getMinutes() * 60 * 1000) + (zeit.getSeconds() * 1000) + zeit.getMilliseconds();
intUpdate = setTimeout("ajax_read('chat.txt?x=" + ms + "')", waittime)
}
}

xmlhttp.open('GET',url,true);
xmlhttp.send(null);
}

/* Request for Writing the Message */
function ajax_write(url){
if(window.XMLHttpRequest){
xmlhttp2=new XMLHttpRequest();
if(xmlhttp2.overrideMimeType){
xmlhttp2.overrideMimeType('text/xml');
}
} else if(window.ActiveXObject){
try{
xmlhttp2=new ActiveXObject("Msxml2.XMLHTTP");
} catch(e) {
try{
xmlhttp2=new ActiveXObject("Microsoft.XMLHTTP");
} catch(e){
}
}
}

if(!xmlhttp2) {
alert('Giving up :( Cannot create an XMLHTTP instance');
return false;
}

xmlhttp2.open('GET',url,true);
xmlhttp2.send(null);
}

/* Submit the Message */
function submit_msg(){
nick = document.getElementById("chatnick").value;
msg = document.getElementById("chatmsg").value;

if (nick == "") {
check = prompt("please enter username:");
if (check === null) return 0;
if (check == "") check = "anonymous";
document.getElementById("chatnick").value = check;
nick = check;
}

document.getElementById("chatmsg").value = "";
ajax_write("w.php?m=" + msg + "&n=" + nick);
}

/* Check if Enter is pressed */
function keyup(arg1) {
if (arg1 == 13) submit_msg();
}

/* Start the Requests! ;) */
var intUpdate = setTimeout("ajax_read('chat.txt')", waittime);

</script>
   

E dovrebbe essere inserito alla fine del body (prima del tag </body>). L'ho inserito così come è aprendo il template, ma non fa alcun effetto. Ho provato anche a disattivare l'editor quando lo scrivo nel template, ma niente come se non lo vedesse proprio. Intanto se non lo vede proprio nel corpo del body la funzione non la fa (nell'head non va ...).

Grazie 1000 a chi si fa venire una idea  ;)   
: Re:Come inserire uno javascript nell'index del template
: tonicopi 29 Sep 2010, 19:33:45
Ma perchè non scarichi, modifichi e ricarichi la index.php del template via ftp?
: Re:Come inserire uno javascript nell'index del template
: webskip 30 Sep 2010, 10:55:42
In effetti non è che l'editor di joomla non prende le righe di programma in javascript (come avviene nella opzione html degli articoli dove gli script sono automaticamente cancellati).
L'editor Joomla lo prende la riga di comando e solo che la riga non produce alcun effetto.
Grazie della risposta comunque ...