Forums ProgMatique Forum Index Forums ProgMatique
Programmation (C/C++, JAVA, PHP, JavaScript, ...) et Informatique (Webmaster, Web)
Retour au site Progmatique

[JS] Compatibilité IE / FF : higlight d'un lien à partir d'une frame

 
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Forums ProgMatique Forum Index » Programmation » Javascript / AJAX
Previous topic :: Next topic  
Author Message
emmeline.a


Offline


Joined: 20 Jul 2010
Posts: 2


PostPosted: Tue 20 Jul 2010 - 15:29    Post subject: [JS] Compatibilité IE / FF : higlight d'un lien à partir d'une frame Reply with quote

Salut,

J'ai un problème de compatibilité entre IE (KO) et FF (Ok).

Exposition du problème :
J'ai une page Index qui contient 2 frames, Principal.htm (mon moteur de recherche) et Sommaire.htm (dans la partie gauche de la page).
Les réponses à la recherche sont affichées dynamiquement dans la même page Principal.htm.
Je voudrais que lorsque je clique sur une réponse, le lien correspondant au div du sommaire soit highlighter.
Donc dans FF, nikel, dans IE rien du tout, même pas de message d'erreur.
Y a-t-il des problèmes de compatibilités avec la fonction GetElementByID ?
J'ai bien trouvé une fonction permettant de la rendre compatible avec tous les navigateurs mais sans succès.

Je mets mon code à disposition au cas où (ne prenez pas peur, la taille de l'ascenseur est dûe à la dernière fonction JS, que j'ai récupéré sur un site)...
Chercher dans le moteur 'Lien' et vous verrez que dans IE rien ne change dans le sommaire, alors que dans FF, le mot 'Sommaire' appraît highlighter en bleu.

Page principale Principal.htm:

Code:
<html><head>
<script language="Javascript" src="db.js"></script>
<script language="Javascript" src="search.js"></script>
</head>
<body>
<!-- saved from url=(0013)about:internet -->
<script language="Javascript">
initSearch();
</script> 
</body>
</html>


Page de sommaire (à gauche) : Sommaire.htm

Code:
<html><head>
<title>Sommaire</title>
<base target="main">
</head>
<body>
<span id="1">Sommaire</span>
</body>
</html>


Page de frame : Index.htm

Code:
  <frameset name="tocbody" framespacing="5" cols="248,*">    <noframes>
    <p>This page uses frames, but your browser doesn't support them.</p>
    </noframes>
    <frame name="contents" target="main" src="sommaire.htm" scrolling="auto" resize="no">
    <frame name="main" src="principal.htm" scrolling="auto" target="_self">
  </frameset>
</frameset>


Base de données JS: db.js

Code:
/* Search - Database file */var records_count=0; 
v1 = new Array(records_count);
v2 = new Array(records_count);
v3 = new Array(records_count);
var a=0;
function fresh(url1) {
parent.main.location.href= url1;
}

////////////////////////////////////////////////////////////////
a +=1
v1[a]="<a onclick=parent.contents.document.getElementById('1').style.background='blue' href=javascript:fresh('Lien_suivi.htm')>Lien suivi</a>"
v2[a]="lien suivi"
v3[a]="" 
////////////////////////////////////////////////////////////////
records_count = a;


Fonction de recherche JS (je sais elle est longue et je ne comprend que la moitié des choses mais elle fonctionne... jusqu'à maintenant) search.js

Code:
/* Based on Search version5.0 */// Le nom du fichier
var searchname = 'principal.htm';
// Le nom et l'adresse du boutonvar usebannercode = true;
var ButtonCode = "<img src='../DLIP/searchbutton.gif' border=0>";
var usebannercode = true;
// Création du corps de la page HTML
function templateBody()
{
////// modifications possibles ///////
  document.write('<html><head><title>Rechercher</title></head><body bgcolor="#ffffff" text="#000000" link="#000099" vlink="#996699" alink="#996699"><table width=0><tr><td width=0><font color="#000000"><font face="Arial" size="14"><font face=Arial, Verdana size=6><b>Rechercher</font></font></center></td><td width=0><div align=right></div></td></tr></table><center><table border=0 width=0><tr><td>');
}
// Fin de la page
function templateEnd()
{
  document.write('</td></tr></table></font></center></body></html>');
}
////// fin de  modifications ///////
function bannerCode()
{
}
//-----------------------------------------------------------------------------------------------
var finds =0;
var sites =0;
var version = "v5.0"
var andresult = false;
var SortResults = true;
var display_start = 1; 
var displast = 20;
function searchAll(keyword)
{
 var timeA=new Date();
 var nw=1;
 finds=0;
 sites=0;
 var x = parseIt(keyword);
 if(x == -1) return;
 total_keywords=x;
 document.open();
 document.clear();
 document.write('<link rel="stylesheet" href="search.css">');
 AddBody();
 if (keyword.length>50) keyword=keyword.substring(0,60)+"...";
 results=new makeArray(records_count,1);
 order=new makeArray(records_count,1);
 for (q=1; q<=results.length; q++)
  {
   results[q]=0;
   order[q]=q;
 }
 data=new makeRecordLinks(records_count);
 while(keywords[nw].length > 1)
 {
   search(data,keywords[nw]);
   nw++;
 } 
 if (andresult)
 {
   for (a=1; a<=results.length; a+=1)
   {
     if (results[a]>0)
     {
       if (results[a]<=(total_keywords-1)*2)
       {
         results[a]=0;
         sites-=1;
       }
     }
   }
 }
 var temp =0;
 if ((SortResults==true)&&(keywords!='[all]'))
 {
    for (a=results.length; a>=2; a-=1)
   {
     for (b=1; b<a; b+=1)
     {
       if (results[order[a]]>results[order[b]])
       {
         temp=order[b];
         order[b]=order[a];
         order[a]=temp;
       }
     }
   }
 } 
  else
  {
   b=0;
   for (a=results.length; a>=2; a-=1)
   {
     if (results[a]>0)
     {
       order[b]=a;
       b++
     }
   }
 }
 // Now we build the output page
 displast=display_start+20;
 if (displast>sites) displast=sites+1;
 var timeB=new Date();
////// modifications possibles ///////
 document.write("<center><h3>R&eacute;sultats : <b>"+display_start+"-"+(displast-1)+"</b> de <b>"+sites+"</b> pour   <b>"+keyword+"</b>. Dur&eacute;e de la recherche : <b>"+((timeB-timeA)/1000)+"</b> secondes.</h3></center>");
 if (finds==0)
 {
   document.write("<h3><font color=green>Pas de r&eacute;sultats pour  <b>''"+keyword+"''</b>.</font></h3>"+
   "<p>Votre recherche sur - <b>"+keyword+"</b> - n'a trouv&eacute; aucun document correspondant dans la base de   donn&eacute;es.</p>"+
   "<ul><LI>Assurez-vous que les mots sont bien orthographi&eacute;s.</li>"+
   "<LI>Essayez avec moins de mots.</li>"+
   "<LI>Essayez d\'autres mots-clés.</li></ul></span>"+
   "</p>");
////// fin de  modifications ///////   
   DisplaySearch();
   document.close();
   return
  }
 q2=display_start;
 q3=displast;
 for (q=display_start; q<q3;)
 {
   if (results[order[q]]>0)
   {
     document.write("<span class='xtitle'>"+data[order[q]].v1+"</span><br>");
     x1=v1[order[q]].indexOf('http://')+7;
     if (x1==6) x1=v1[order[q]].indexOf('href=')+5;
     x2=v1[order[q]].indexOf('>');
     if (x1>0 && x2>0)
     {
       tmp=v1[order[q]].substring(x1,x2);
       x2=tmp.indexOf(' ');
       if (x2>0) tmp=tmp.substring(0,x2);
       if (tmp.substring(0,1)=="'") tmp=tmp.substring(1,tmp.length-1);
       if (tmp.substring(0,1)=='"') tmp=tmp.substring(1,tmp.length-1);
       document.write("<table border=0 width=500><tr><td><span class='xresult'>"+v3[order[q]]+"</span></td></tr></table><span class='xlocation'></span><br><br>");
//document.write("<table border=0 width=500><tr><td><span class='xresult'>"+v3[order[q]]+"</span><br><br>");
     }
     q2++;
    }
   q+=1;
 }
 if (finds>20)
 {
   document.write("<BR>");
   pages=Math.round(finds/20);
   if (finds%20<6) pages++;
 // Create the parameter string
   paramstring=searchname+"?keywords="+keyword+"&and="+andresult+"&sort="+SortResults;
   document.write("<center><span class='xsmall'>");
////// modifications possibles ///////
   if (display_start>1) document.write("<a href='"+paramstring+"&disp="+(display_start-20)+"'>page pr&eacute;c&eacute;dente</a>");
   document.write("&nbsp;&nbsp;&nbsp;");
   for (i=1; i<=pages;)
    {
     if ((((i-1)*20)+1)<=sites)
      {
       document.write("<a href='"+paramstring+"&disp="+(((i-1)*20)+1)+"'>"+i+"</a>&nbsp&nbsp ");
     }
     i++;
   }
   document.write("&nbsp;&nbsp;&nbsp;");
   if (displast<=sites) document.write("<a href='"+paramstring+"&disp="+(displast)+"'>page suivante</a>");
   document.write("</span></center>");
 }
////// fin de  modifications ///////   
 DisplaySearch();
 document.close();
}
function Cat()
{
 document.open();
 document.clear();
 AddBody();
 DisplaySearch();
 document.close();
}

function makeArray(n,vartype) 
{
 this.length = n;
 for (var k = 1; k <= n; k++) 
  {
   if (vartype==0)
    {
     this[k] = "";
   }
    else
    {
     this[k] = 0;
   }
 }
 return this;
}               
function stripInput(key)
{
 while(key.substring(0,1) == ","  || key.substring(0,1) == " " ) key = key.substring(1,key.length);
 while(key.substring(key.length-1,key.length) == "," || key.substring(key.length-1,key.length) == " ") key =    key.substring(0,key.length-1);
 return key;
}
function parseIt(key) 
{
 key = stripInput(key)+" ";
 var y = 1;
 while(key.indexOf(" ") > 0)
 {
   if (key.substring(0,1)=='"')
   {
     var pos=key.indexOf('"',2);
     keywords[y]=key.substring(1,pos);
     keywords[y]=stripInput(keywords[y]);
     y++;
     key=key.substring(pos+1,key.length);
   }
    else
    {
     var pos=key.indexOf(' AND ');
     if ((pos>0) && (key.indexOf(' ')>=pos))
     {
       pos=key.indexOf(' ',pos+5);
       keywords[y]=key.substring(0,pos);
       keywords[y]=stripInput(keywords[y]);
       y++;
       key=key.substring(pos+1,key.length);
       if (key.substring(0,4)=='AND ')
       {
         pos=keywords[y-1].indexOf(' ')+5;
         key=keywords[y-1].substring(pos,keywords[y-1].length)+' '+key;
       }
     }
      else
      {
       var pos=key.indexOf(' OR ');
       if ((pos>0) && (key.indexOf(' ')>=pos))
       {
         pos=key.indexOf(' ');
         keywords[y]=key.substring(0,pos);
         keywords[y]=stripInput(keywords[y]);
         if (keywords[y]!=keywords[y-1]) y++;
         key=key.substring(pos+1,key.length);
         pos=key.indexOf('OR ');
         key=key.substring(pos+3,key.length);
         pos=key.indexOf(' ');
         keywords[y]=key.substring(0,pos);
         keywords[y]=stripInput(keywords[y]);
         y++;
         key=key.substring(pos+1,key.length);
         if (key.substring(0,3)=='OR ') key=keywords[y-1]+' '+key;
       }
        else
        {
         var pos = key.indexOf(" ");
         keywords[y]=key.substring(0,pos);
         keywords[y] = stripInput(keywords[y]); 
         y++;
         if(y > 50) return -1
           key=key.substring(pos+1,key.length);
       }
     }
   }
 }
 return y-1;
}
var keywords = new makeArray(50,0);
var results;
var foundword;
var data;
var order;
var total_keywords;
function dataEntry ()
{
 this.v1="";
 this.v2="";
 return this;
}
function makeRecordLinks(size)
{
 this.length = size;
 for (var r=1; r<= size; r++) 
 {
    this[r] = new dataEntry();
   this[r].v1 = v1[r];
   this[r].v2 = v2[r]; 
 }
 return this;
}

// Page HTML telle que vue à l'écran
function AddBody()
{
 var keytext='"'+searchname+'?keywords="+';
 var andtext='"&and="+';
 document.write('<script>function doSearch(){'+
 'searchwords=document.searchform.searchwords.value; '+
 'while (searchwords.indexOf(" ")>-1){ pos=searchwords.indexOf(" ");'+
 'searchwords=searchwords.substring(0,pos)+"+"+searchwords.substring(pos+1); }'+
 'document.location='+keytext+' searchwords+'+andtext+'"0"}'+
 '<'+'/'+'script>'
 );
 templateBody();
////// modifications possibles ///////
 document.write('<html><head>');
[b] document.write("<SCRIPT language='javascript'>");
 document.write('if(!document.getElementById){');
 document.write('  if(document.all){');
 document.write('    document.getElementById=function(){');
 document.write('if(typeof document.all[arguments[0]]!="undefined"){return document.all[arguments[0]]}else{return null}');
 document.write('    }');
 document.write('  }else if(document.layers){');
 document.write('    document.getElementById=function(){');
 document.write('if(typeof document[arguments[0]]!="undefined"){return document[arguments[0]]}else{return null}');
 document.write('    }');
 document.write('  }');
 document.write('}</SCRIPT>');[/b]
 document.write('</head>');
 document.write('<p><br></p><table width=0><tr><td width=0><font color="#000000"><font face="Arial" size="10"><font face=Arial, Verdana size=2>Taper le ou les mots correspondant(s) à la recherche.</font></font></td><td width=0></td></tr></table><table border=0 width=0><tr><td>');
 document.write("<br><form name='searchform' method='post' action='javascript:doSearch()'><table border='0' width='100%'><tr><td  align='center'><font face='Arial' size='6'><input name='searchwords' type='text' size='65'>&nbsp;&nbsp;<a  href='javascript:doSearch()'>"+ButtonCode+"</a></font></td></tr></table></form>");
 document.write('<html><p><br></p><table width=0><tr><td width=0><font color="#000000"><font face="Arial" size="10"><font face=Arial, Verdana size=2>Lorsque plusieurs mots clés sont saisis, la recherche s\'effectue dans les pages où au moins l\'un des mots apparaît.</font></font></td><td width=0></td></tr></table><table border=0 width=0><tr><td>');
 document.write('<html><font face="Arial" size="10"><font face=Arial, Verdana size=2>Sacisir AND entre chaque mots clés (exemple : mot1 AND mot2), afin de rechercher les pages dans lesquelles tous les mots clés saisis apparaissent.</font></font></td><td width=0></td></tr></table><table border=0 width=0><tr><td>');
 //document.write(navigator.appName);
  if (navigator.appName!="Netscape")
    document.searchform.searchwords.focus();
////// fin de  modifications ///////   
 if (usebannercode) bannerCode();
}

// Inscription Bas de page + fin de code HTML pour la page
function DisplaySearch()
{
////// modifications possibles ///////
//document.write("<center><hr size=1></center>")
// document.write("<Font size=-1><center>R&eacute;alis&eacute; avec <a href=http://www.twicefun.com/just4fun>Search  "+version+"</a>  - Free Javascript SearchEngine</center></font>");
////// fin de  modifications ///////  
 templateEnd();
}
function search(records, keyword)
{
 var hit=0;
 var addcomplete=0;

 for (q=1; q<=records.length; q++) 
  {
   addcomplete=0;
   search_parm=records[q].v2.toLowerCase()+" "+v3[q].toLowerCase();

   if (keyword.indexOf(' AND ')>0)
   {
     firstword=keyword.substring(0,keyword.indexOf(' '));
     lastword=keyword.substring(keyword.indexOf(' AND ')+5,keyword.length);
     if ((search_parm.indexOf(" "+firstword+" ") != -1) && (search_parm.indexOf(" "+lastword+" ")!= -1 ))
     {
       hit++;
       finds++;
       if(hit < 2)
       { 
         if (results[q]==0) sites++;
           results[q] +=2;
       } 
     }
   }
    else
    {
     keyword=keyword.toLowerCase();
     if ((search_parm.indexOf(" "+keyword+" ") != -1) ||(keyword=="[all]"))
     {
       hit++;
       finds++;
       if(hit<2)
       { 
         if (results[q]==0) sites++;
         results[q]+=2;
       } 
     }
      else
      {
 // check for a half hit (ie. search:share find:SHAREware)
       if (search_parm.indexOf(keyword) != -1)
       {
         hit++;
         finds++;
         if(hit < 2)
         {
           if (results[q]==0) sites++;
           results[q]+=1;
           x=search_parm.indexOf(keyword)+keyword.length;
           pos=search_parm.substring(1,x-keyword.length);
           while (pos.indexOf(" ")!=-1)
           {
             y=pos.indexOf(" ");
             pos=pos.substring(y+1,pos.length);
           }
           if (pos.length<=2) addcomplete++;
           pos=search_parm.substring(x,search_parm.length);
           fullresult=search_parm.substring(x,x+pos.indexOf(" "));
     
           if (fullresult.length<=2) addcomplete++;
           if (addcomplete>1) results[q]+=1;
         }
       }
      }
     }
     hit=0;
  } 
}                                       
var searchwords = '';
var newload = true;
function countParams(text)
{
 pos=-1;
 tmp = "";
 if (text=='') return 0;
 text=text+'&';
 i=0;
 while (text.length>0)
 {
   pos=text.indexOf('&',0);
   tmp=text.substring(pos+1);
   text=tmp;
   i++;
 }
 return i;

function getCommand(text,val)
{
 pos=-2;
 tmp = "";
 text=text+'&';
 for (i=0; i<=val;)
 {
   pos2=pos+2;
   pos=text.indexOf('&',pos2);
   tmp=text.substring(pos,pos2-1);
   i++;
 }
 text=tmp;
 pos=text.indexOf('=',0);
 if (pos!=-1) tmp=text.substring(pos,0);
 tmp=tmp.toLowerCase();
 return tmp;
}
function getValues(text,val)
{
 pos=-2;
 tmp = "";
 text=text+'&';
 for (i=0; i<=val;)
 {
   pos2=pos+2;
   pos=text.indexOf('&',pos2);
   tmp=text.substring(pos,pos2-1);
   i++;
 }
 text=tmp;
 pos2=text.indexOf('=',0)+1;
 if (pos2!=-1)
 {
   tmp=text.substring(pos2);
 } 
  else 
  { 
   tmp='' 
 }

 pos=-2;
 text=tmp; 
 if (text.indexOf('%20')>0)
 {
   pos=text.indexOf('%20',0);
   tmp=text.substring(0,pos2-4)+' '+text.substring(pos2-1,text.length);
   text=tmp;
 }
 return tmp;
}  
function initSearch()
{
 if (searchwords!='')
 {
   searchAll(searchwords);
 }
  else 
  {
   if (newload) Cat();
 }
}
function doParamStuff(findw)
{
 Myparams=countParams(findw);
 if (Myparams>0)
 {
   for (cnt=0; cnt<Myparams;)
   {
     tempw=getCommand(findw,cnt);
     tempv=getValues(findw,cnt);
     if (tempw=='keywords')
     {
       searchwords=getValues(findw,cnt);
       origsearchwords=searchwords;
       while (searchwords.indexOf('+')>-1)
       {
         pos=searchwords.indexOf('+');
         searchwords=searchwords.substring(0,pos)+' '+searchwords.substring(pos+1);
       }
     }
     if (tempw=='sort')
     {
       if ((tempv=='0')||(tempv=='false'))
       {
         SortResults=false;
       }
        else
        {
         SortResults=true;
       }
     }
    
     if (tempw=='and')
     {
       if ((tempv=='1')||(tempv=='true'))
       {
         andresult=true;
       }
        else
        {
         andresult=false;
       }
     }
     if (tempw=='disp') display_start=parseInt(tempv);
     cnt +=1;
   }
 }
}
findw=document.location.search;
findw="&"+findw.substring(1,findw.length);
while (findw.indexOf('%20')>0)
{
 pos2=findw.indexOf('%20',0);
 tmp=findw.substring(0,pos2)+' '+findw.substring(pos2+3,findw.length);
 findw=tmp;
}
doParamStuff(findw);


Le code en gras est ce que j'ai ajouté pour que le GetElementById soit reconnu par IE mais ça ne marche pas.
Quelqu'un a une idée ?

A+
Back to top
emmeline.a


Offline


Joined: 20 Jul 2010
Posts: 2


PostPosted: Wed 21 Jul 2010 - 07:53    Post subject: [JS] Compatibilité IE / FF : higlight d'un lien à partir d'une frame Reply with quote

Histoire d'assurer le suivi, voilà la réponse au problème :
IE ne reconnait pas le "parent" dans mon cas.
-> v1[a]="<a onclick=\"if(parent.contents){parent.contents.document.getElementById('1').style.backgroundColor = 'blue'}else{top.contents.document.getElementById('1').style.backgroundColor = 'blue'}\" href=\"javascript:fresh('Lien_suivi.htm')\">Lien suivi[/url]"

A+
Back to top
Simon
Administrateur
Administrateur

Offline


Joined: 08 May 2005
Posts: 954
Localisation: France


PostPosted: Wed 21 Jul 2010 - 16:53    Post subject: [JS] Compatibilité IE / FF : higlight d'un lien à partir d'une frame Reply with quote

Bonjour,
Content de voir que tu as trouvé la solution, merci de l'avoir partagé
_________________
Simon (SimMaster),
Programmation et informatique
Colorisation syntaxique de codes sources
Outils et services autour de l'adresse IP
Back to top
Visit poster’s website
Display posts from previous:   
This forum is locked: you cannot post, reply to, or edit topics.   This topic is locked: you cannot edit posts or make replies.    Forums ProgMatique Forum Index » Programmation » Javascript / AJAX All times are GMT + 1 Hour
Page 1 of 1

 
Jump to:  

Index | Create a forum | Free support forum | Free forums directory | Report a violation | Conditions générales d'utilisation
Powered by phpBB v2 © 2001, 2005 phpBB Group ¦ Theme: subSilver++