Forum |  HardWare.fr | News | Articles | PC | S'identifier | S'inscrire | Shop Recherche
3055 connectés 

  FORUM HardWare.fr
  Programmation
  HTML/CSS

  Conflit entre deux .js[Resolu]

 


 Mot :   Pseudo :  
 
Bas de page
Auteur Sujet :

Conflit entre deux .js[Resolu]

n°1953351
bustaflexx
Posté le 28-12-2009 à 02:45:54  profilanswer
 

Bonjour,
 
Le deux scripts marchent tout à fait quand ils sont séparés.
Par contre, une fois mis ensembles, l'un des deux ne fonctionne pas.
J'ai un peu cherché et il semble que c'est un problème avec les deux onload.
J'ai essayé window.onload= {Tabs.Init; LoadJS;}
Mais ça ne marche pas non plus
Any idea please
 
Ci-bas les deux scripts lib.js et tabs.js  
 

Code :
  1. // Bibliothèque Objet
  2. function Ident(Obj){ return (document.all)?document.all[Obj]:document.getElementById(Obj); }
  3. function posX(Obj){ return (Obj.offsetParent)?(Obj.offsetLeft + posX(Obj.offsetParent)):(Obj.offsetLeft); }
  4. function posY(Obj){ return (Obj.offsetParent)?(Obj.offsetTop + posY(Obj.offsetParent)):(Obj.offsetTop); }
  5. function posW(Obj){ return (Obj.offsetParent)?(Obj.offsetWidth + posX(Obj.offsetParent)):(Obj.offsetWidth); }
  6. function posH(Obj){ return (Obj.offsetParent)?(Obj.offsetHeight + posY(Obj.offsetParent)):(Obj.offsetHeight); }
  7. // Détection du click sur menuLeft
  8. function menuDynam(){
  9. for(m=1; m<5; m++){
  10.  if(document.all){
  11.   Ident('menu'+m).onmousedown=thisMenu;
  12.  }else{
  13.   Ident('menu'+m).addEventListener("mousedown",thisMenu, false);
  14.  }
  15. }
  16. }
  17. function thisMenu(e){ devl('s'+this.id); }
  18. // fonction pour réglementation de l'attribut 'target' du W3C
  19. function TargetBlank() {
  20. if (!document.getElementsByTagName) return;
  21. var anchors = document.getElementsByTagName("a" );
  22. for (var i=0; i<anchors.length; i++) {
  23.  var anchor = anchors[i];
  24.  if (anchor.getAttribute("href" ) && anchor.getAttribute("rel" ) == "external" ) anchor.target = "_blank";
  25. }
  26. }
  27. // Fonction menu developpent
  28. function devl(id) {
  29. var d = Ident(id), e=false;
  30. if(d){ if(d.style.display=='block') e=true; }
  31. for (var i = 1; i<=10; i++) {
  32.  if (Ident('smenu'+i)) {Ident('smenu'+i).style.display='none';}
  33. }
  34. if(d){
  35.  d.style.display=(e==false)?'block':'none';
  36. }
  37. }
  38. function LoadJS(){
  39.  TargetBlank();
  40.  devl();
  41.  menuDynam();
  42. }
  43. // Executer la fonction
  44. window.onload=LoadJS;


 

Code :
  1. // CSS helper functions
  2. CSS = {
  3.     // Adds a class to an element.
  4.     AddClass: function (e, c) {
  5.         if (!e.className.match(new RegExp("\\b" + c + "\\b", "i" )))
  6.             e.className += (e.className ? " " : "" ) + c;
  7.     },
  8.     // Removes a class from an element.
  9.     RemoveClass: function (e, c) {
  10.         e.className = e.className.replace(new RegExp(" \\b" + c + "\\b|\\b" + c + "\\b ?", "gi" ), "" );
  11.     }
  12. };
  13. // Functions for handling tabs.
  14. Tabs = {
  15.     // Changes to the tab with the specified ID.
  16.     GoTo: function (contentId, skipReplace) {
  17.         // This variable will be true if a tab for the specified
  18.         // content ID was found.
  19.         var foundTab = false;
  20.         // Get the TOC element.
  21.         var toc = document.getElementById("toc" );
  22.         if (toc) {
  23.             var lis = toc.getElementsByTagName("li" );
  24.             for (var j = 0; j < lis.length; j++) {
  25.                 var li = lis[j];
  26.                 // Give the current tab link the class "current" and
  27.                 // remove the class from any other TOC links.
  28.                 var anchors = li.getElementsByTagName("a" );
  29.                 for (var k = 0; k < anchors.length; k++) {
  30.                     if (anchors[k].hash == "#" + contentId) {
  31.                         CSS.AddClass(li, "current" );
  32.                         foundTab = true;
  33.                         break;
  34.                     } else {
  35.                         CSS.RemoveClass(li, "current" );
  36.                     }
  37.                 }
  38.             }
  39.         }
  40.         // Show the content with the specified ID.
  41.         var divsToHide = [];
  42.         var divs = document.getElementsByTagName("div" );
  43.         for (var i = 0; i < divs.length; i++) {
  44.             var div = divs[i];
  45.             if (div.className.match(/\bcontent\b/i)) {
  46.                 if (div.id == "_" + contentId)
  47.                     div.style.display = "block";
  48.                 else
  49.                     divsToHide.push(div);
  50.             }
  51.         }
  52.         // Hide the other content boxes.
  53.         for (var i = 0; i < divsToHide.length; i++)
  54.             divsToHide[i].style.display = "none";
  55.         // Change the address bar.
  56.         if (!skipReplace) window.location.replace("#" + contentId);
  57.     },
  58.     OnClickHandler: function (e) {
  59.         // Stop the event (to stop it from scrolling or
  60.         // making an entry in the history).
  61.         if (!e) e = window.event;
  62.         if (e.preventDefault) e.preventDefault(); else e.returnValue = false;
  63.         // Get the name of the anchor of the link that was clicked.
  64.         Tabs.GoTo(this.hash.substring(1));
  65.     },
  66.     Init: function () {
  67.         if (!document.getElementsByTagName) return;
  68.         // Attach an onclick event to all the anchor links on the page.
  69.         var anchors = document.getElementsByTagName("a" );
  70.         for (var i = 0; i < anchors.length; i++) {
  71.             var a = anchors[i];
  72.             if (a.hash) a.onclick = Tabs.OnClickHandler;
  73.         }
  74.         var contentId;
  75.         if (window.location.hash) contentId = window.location.hash.substring(1);
  76.         var divs = document.getElementsByTagName("div" );
  77.         for (var i = 0; i < divs.length; i++) {
  78.             var div = divs[i];
  79.             if (div.className.match(/\bcontent\b/i)) {
  80.                 if (!contentId) contentId = div.id;
  81.                 div.id = "_" + div.id;
  82.             }
  83.         }
  84.         if (contentId) Tabs.GoTo(contentId, true);
  85.     }
  86. };
  87. // Hook up the OnLoad event to the tab initialization function.
  88. window.onload = Tabs.Init;
  89. // Hide the content while waiting for the onload event to trigger.
  90. var contentId = window.location.hash || "#Introduction";
  91. if (document.createStyleSheet) {
  92.     var style = document.createStyleSheet();
  93.     style.addRule("div.content", "display: none;" );
  94.     style.addRule("div" + contentId, "display: block;" );
  95. } else {
  96.     var head = document.getElementsByTagName("head" )[0];
  97.     if (head) {
  98.         var style = document.createElement("style" );
  99.         style.setAttribute("type", "text/css" );
  100.         style.appendChild(document.createTextNode("div.content { display: none; }" ));
  101.  style.appendChild(document.createTextNode("div" + contentId + " { display: block; }" ));
  102.         head.appendChild(style);
  103.     }
  104. }


Message édité par bustaflexx le 30-12-2009 à 17:08:11
mood
Publicité
Posté le 28-12-2009 à 02:45:54  profilanswer
 

n°1954034
Nethacker
rule televisions, rule minds
Posté le 30-12-2009 à 17:01:04  profilanswer
 

Si t'as firebug, (extension firefox) essaye de voir s'il y'a des erreurs JavaScript,
sinon la console d'erreurs de FF, fera l'affaire aussi .


Message édité par Nethacker le 30-12-2009 à 17:01:30
n°1954530
GordonF_69
Posté le 03-01-2010 à 02:07:35  profilanswer
 

Dans les 2 script il y a un "window.onload=qqc"
 
Il ne peux y avoir cette fonction qu'une fois (la fin de chargement d'une page n'apparait qu'une fois)
 
Par contre tu peux tenter de contourner en faisant ca :

Code :
  1. function mon_onload_a_moi()
  2. {
  3. LoadJS()
  4. Tabs.Init();
  5. }
  6. window.onload=mon_onload_a_moi;


 
Bien sur en virant les autre onload dans les .js


Message édité par GordonF_69 le 03-01-2010 à 02:08:16
n°1954532
bustaflexx
Posté le 03-01-2010 à 02:43:25  profilanswer
 

Merci à tous pour vos messages, le problème est résolu ::


Aller à :
Ajouter une réponse
  FORUM HardWare.fr
  Programmation
  HTML/CSS

  Conflit entre deux .js[Resolu]

 

Sujets relatifs
[Résolu]Caractères spéciaux et blancs à retirer[SGBD] [semi-résolu] Comment organiser mes données de façon optimale ?
[VBscript] comparaison de chaine/filtre(résolu)[C#] (RESOLU) GetSchemaTable trop de champs !
[RESOLU]Serialize de session/ IE ? :/[Résolu] Copier la structure d'un site
[JS ] Conflit ***.js avec prototype.js[Resolu] Activer la fonction mail
[Résolu] Conflit entre deux fichiers js (plusieurs onLoad)[resolu] Conflit Virtuel Static ( Factory Design Pattern )
Plus de sujets relatifs à : Conflit entre deux .js[Resolu]


Copyright © 1997-2022 Hardware.fr SARL (Signaler un contenu illicite / Données personnelles) / Groupe LDLC / Shop HFR