Hi all!
I've wrote this code:
[code=javascript]
<script type="text/javascript">
var largImg;
var altImg;
var txtTop = '<b>Ottima scelta!</b> Ora compila il form e premi "Ricevi banner". Il codice HTML ti verrà mostrato in questa pagina e, per comodità, ti verrà inviato, via mail, all\'indirizzo da te fornito. Se invece vuoi cambiare il banner premi "Seleziona banner"';
var txtButton = 'Cambia banner';
var testo = '';
var maxLarg = 450;
var maxAlt = 80;
var diffLarg;
var diffAlt;
var diff;
function setBanner(url, id){
window.opener.d ocument.getElem entById("testoR eceive").innerH TML = txtTop;
window.opener.d ocument.getElem entById("banner Sel").value = txtButton;
largImg = window.document .getElementById (id).width;//parseInt(url.sp lit("/")[url.split("/").length-1].split("_")[0].split("x")[0]);
altImg = window.document .getElementById (id).height;//parseInt(url.sp lit("/")[url.split("/").length-1].split("_")[0].split("x")[1]);
txtLarg = "Larghezza: " + largImg + "px";
txtAlt = "Altezza: " + altImg + "px";
diff = (largImg - altImg) + Math.abs(largIm g - altImg);alert(d iff);
testo += '<table cellpadding="0" cellspacing="0" width="100%">'; alert(1);
testo += '<tr>';
testo += '<td valign="middle" >';
testo += '<img id="previewBann er" src="' + url + '"/>';
testo += '</td>';
if(diff != 0){
testo += '</tr><tr>';
}
testo += '<td valign="middle" >';
testo += txtLarg + '<br/><br/>';
testo += txtAlt;
testo += '</td>';
testo += '</tr>';
testo += '</table>';
window.opener.d ocument.getElem entById("divBan ner").innerHTM L = testo;
diffLarg = (largImg - maxLarg) + Math.abs(largIm g - maxLarg);
diffAlt = (altImg - maxAlt) + Math.abs(altImg - maxAlt);
if(diffLarg != 0){
if(diffAlt != 0){
var propDiff = (Math.abs(largI mg - maxLarg) - Math.abs(altImg - maxAlt)) + Math.abs(Math.a bs(largImg - maxLarg) - Math.abs(altImg - maxAlt));
if(propDiff != 0){
window.opener.d ocument.getElem entById("previe wBanner").style .width = maxLarg + 'px';
}
else{
window.opener.d ocument.getElem entById("previe wBanner").style .height = maxAlt + 'px';
}
}
else{
window.opener.d ocument.getElem entById("previe wBanner").style .width = maxLarg + 'px';
}
}
else{
if(diffAlt != 0){
window.opener.d ocument.getElem entById("previe wBanner").style .width = maxAlt + 'px';
}
else{
window.opener.d ocument.getElem entById("previe wBanner").style .width = largImg + 'px';
window.opener.d ocument.getElem entById("previe wBanner").style .height = altImg + 'px';
}
}
window.close();
}
</script>
[/code]
It's simple:
1) the caller send an url like "140x257_1. jpg" and an id generated by xsl
2) the function substitute what's in caller page's "testoRecei ve" div with a pre-set variable
3) change the value of a caller page's button
4) get the dimension of the image
5) check which dimension is the higher with a difference. If largImg is higher than altImg, diff will not be 0.
Ex: (5 - 3) + abs(5-3) = 2 + 2 = 4; Ex2: (3 - 5) + abs(3 - 5) = -2 + 2 = 0
6) insert into variable "testo" the HTML code to create a table.
7) use variable testo as HTML of caller page's divBanner div
8) check if the dimensions are higher than a max. If it's, resize the image.
9) set image's width and height.
My problem is: firefox execute the function until "alert(diff )" included. From next istruction don't do anything.
I've tried to remove all table's attribute but nothing change, I've tried to insert <tbody> but nothing.
Someone would help me please?
Thank you.
I've wrote this code:
[code=javascript]
<script type="text/javascript">
var largImg;
var altImg;
var txtTop = '<b>Ottima scelta!</b> Ora compila il form e premi "Ricevi banner". Il codice HTML ti verrà mostrato in questa pagina e, per comodità, ti verrà inviato, via mail, all\'indirizzo da te fornito. Se invece vuoi cambiare il banner premi "Seleziona banner"';
var txtButton = 'Cambia banner';
var testo = '';
var maxLarg = 450;
var maxAlt = 80;
var diffLarg;
var diffAlt;
var diff;
function setBanner(url, id){
window.opener.d ocument.getElem entById("testoR eceive").innerH TML = txtTop;
window.opener.d ocument.getElem entById("banner Sel").value = txtButton;
largImg = window.document .getElementById (id).width;//parseInt(url.sp lit("/")[url.split("/").length-1].split("_")[0].split("x")[0]);
altImg = window.document .getElementById (id).height;//parseInt(url.sp lit("/")[url.split("/").length-1].split("_")[0].split("x")[1]);
txtLarg = "Larghezza: " + largImg + "px";
txtAlt = "Altezza: " + altImg + "px";
diff = (largImg - altImg) + Math.abs(largIm g - altImg);alert(d iff);
testo += '<table cellpadding="0" cellspacing="0" width="100%">'; alert(1);
testo += '<tr>';
testo += '<td valign="middle" >';
testo += '<img id="previewBann er" src="' + url + '"/>';
testo += '</td>';
if(diff != 0){
testo += '</tr><tr>';
}
testo += '<td valign="middle" >';
testo += txtLarg + '<br/><br/>';
testo += txtAlt;
testo += '</td>';
testo += '</tr>';
testo += '</table>';
window.opener.d ocument.getElem entById("divBan ner").innerHTM L = testo;
diffLarg = (largImg - maxLarg) + Math.abs(largIm g - maxLarg);
diffAlt = (altImg - maxAlt) + Math.abs(altImg - maxAlt);
if(diffLarg != 0){
if(diffAlt != 0){
var propDiff = (Math.abs(largI mg - maxLarg) - Math.abs(altImg - maxAlt)) + Math.abs(Math.a bs(largImg - maxLarg) - Math.abs(altImg - maxAlt));
if(propDiff != 0){
window.opener.d ocument.getElem entById("previe wBanner").style .width = maxLarg + 'px';
}
else{
window.opener.d ocument.getElem entById("previe wBanner").style .height = maxAlt + 'px';
}
}
else{
window.opener.d ocument.getElem entById("previe wBanner").style .width = maxLarg + 'px';
}
}
else{
if(diffAlt != 0){
window.opener.d ocument.getElem entById("previe wBanner").style .width = maxAlt + 'px';
}
else{
window.opener.d ocument.getElem entById("previe wBanner").style .width = largImg + 'px';
window.opener.d ocument.getElem entById("previe wBanner").style .height = altImg + 'px';
}
}
window.close();
}
</script>
[/code]
It's simple:
1) the caller send an url like "140x257_1. jpg" and an id generated by xsl
2) the function substitute what's in caller page's "testoRecei ve" div with a pre-set variable
3) change the value of a caller page's button
4) get the dimension of the image
5) check which dimension is the higher with a difference. If largImg is higher than altImg, diff will not be 0.
Ex: (5 - 3) + abs(5-3) = 2 + 2 = 4; Ex2: (3 - 5) + abs(3 - 5) = -2 + 2 = 0
6) insert into variable "testo" the HTML code to create a table.
7) use variable testo as HTML of caller page's divBanner div
8) check if the dimensions are higher than a max. If it's, resize the image.
9) set image's width and height.
My problem is: firefox execute the function until "alert(diff )" included. From next istruction don't do anything.
I've tried to remove all table's attribute but nothing change, I've tried to insert <tbody> but nothing.
Someone would help me please?
Thank you.
Comment