Ciao ragazzi ho un problema.
Nel mio sito voglio dinamicamente modificare il font in dim e stile. Ho utilizzato 2 funzioni js che posto sotto imposta_dim_font e imposta_fontFamily(font) che funzionano perfettamente su IE mentre non hanno alcun effetto su FireFox e Chrome:
function imposta_dim_font(valore) {
if(styleSheetsOK) {
if(targetrule!=null){
alert("targetrule.style.fontSize---"+targetrule.style.fontSize);
targetrule.style.fontSize = valore + 'px';
}
if(targetruleHidden!=null){
alert("targetruleHidden.style.fontSize---"+targetruleHidden.style.fontSize);
targetruleHidden.style.fontSize = valore + 'px';
}
if(targetruleInfo!=null){
alert("targetruleInfo.style.fontSize---"+targetruleInfo.style.fontSize);
targetruleInfo.style.fontSize = valore + 'px';
}
}
}
function imposta_font(font) {
if(styleSheetsOK) {
if(targetrule!=null){
// targetrule.style.font = font;
// targetrule.style.font-family = font;
}
if(targetruleHidden!=null){
// targetruleHidden.style.font = font;
// targetruleHidden.style.font-family = font;
}
if(targetruleInfo!=null){
// targetruleInfo.style.font = font;
// targetruleInfo.style.font-family = font;
}
}
}
function imposta_fontFamily(font) {
if(styleSheetsOK) {
if(targetrule!=null){
targetrule.style.fontFamily = font;
}
if(targetruleHidden!=null){
targetruleHidden.style.fontFamily = font;
}
if(targetruleInfo!=null){
targetruleInfo.style.fontFamily = font;
}
}
}
dove
styleSheetsOK = (document.styleSheets) ? 1 : 0;
IE = ((ind1 = navigator.appVersion.indexOf("MSIE")) > -1) ? 1 : 0;
IE4 = (IE && document.all) ? 1:0;
NN = (navigator.appName.indexOf("Netscape")>-1) ? 1 : 0;
NN4 = (NN && document.layers) ? 1 : 0;
NN6 = (NN && document.getElementById) ? 1:0;
var targetrule;
var targetruleHidden;
var targetruleInfo;
alert("styleSheetsOK---"+styleSheetsOK);
if(styleSheetsOK) {
var trovato = false;
var trovatoHid = false;
var trovatoInfo = false;
for (i=0; i<document.styleSheets.length; i++){
if(IE4){
var documento = document.styleSheets[i];
try{
stile = documento.rules;
}catch (e) {
//System.out.println(documento.href + " NON ACCESSIBILE");
}
}
try{
if(NN6) stile = document.styleSheets[i].cssRules;
for (y=0; y<stile.length; y++){
if(stile[y].selectorText.toLowerCase()==".font_form"){
trovato=true;
alert("trovato---"+trovato);
for (z=0; z<stile.length; z++){
if(stile[z].selectorText.toLowerCase()==".font_form"){
targetrule=stile[z];
alert("targetrule *****---"+targetrule);
break;
}
}
}
if(stile[y].selectorText.toLowerCase()==".camporeadonly"){
trovatoHid=true;
for (z=0; z<stile.length; z++){
if(stile[z].selectorText.toLowerCase()==".camporeadonly"){
targetruleHidden=stile[z];
alert("targetruleHidden---"+targetruleHidden);
break;
}
}
}
if(stile[y].selectorText.toLowerCase()==".stile_font"){
trovatoInfo=true;
for (z=0; z<stile.length; z++){
if(stile[z].selectorText.toLowerCase()==".stile_font"){
targetruleInfo=stile[z];
alert("targetruleInfo---"+targetrule);
break;
}
}
}
if(trovato && trovatoHid){
break;
}
}
if(trovato && trovatoHid){
break;
}
}catch (e) {
//System.out.println(documento.href + " NON ACCESSIBILE");
}
}
}
cos'è che sbaglio???
Mi potete aiutare???
Vi ringrazio in anticipo per vostra attenzione!!
Cy