IdentifiantMot de passe
Loading...
Mot de passe oublié ?Je m'inscris ! (gratuit)
Navigation

Inscrivez-vous gratuitement
pour pouvoir participer, suivre les réponses en temps réel, voter pour les messages, poser vos propres questions et recevoir la newsletter

JavaScript Discussion :

Popup avec balise div


Sujet :

JavaScript

  1. #1
    Inactif  
    Avatar de Kerod
    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    11 672
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 11 672
    Points : 20 778
    Points
    20 778
    Par défaut Popup avec balise div
    Bonjour,
    Je souhaiterai créer une fenetre popup uniquement créee à partir d'une balise div.
    Pourriez vous m'indiquer comment je dois m'y prendre,svp ?

  2. #2
    Membre confirmé
    Avatar de malbaladejo
    Profil pro
    Inscrit en
    Avril 2002
    Messages
    379
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Avril 2002
    Messages : 379
    Points : 527
    Points
    527
    Par défaut
    J'ai un code générer par dreamweaver a te proposer:

    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
    12
    13
    14
    15
    16
    17
    18
    19
    20
    21
    22
    23
    24
    25
    26
    27
    28
    29
    30
    31
    32
    33
    34
    35
    36
    37
    38
    39
    40
    41
    42
    43
    44
    45
    46
    47
    48
    49
    50
    51
    52
    53
    54
    55
    56
    57
    58
    59
    60
    61
    62
    63
    64
    65
    66
    67
    68
    69
    70
    71
    72
    73
    74
    75
    76
    77
    78
    79
    80
    81
    82
    83
    84
    85
    86
    87
    88
    89
    90
    91
    92
    93
    94
    95
    96
    97
    98
    99
    100
    101
    102
    103
    104
    105
    106
    107
    108
    109
    110
    111
    112
    113
    114
    115
    116
    117
    118
    119
    120
    121
    122
    123
    124
    125
    126
    127
    128
    129
    130
    131
    132
    133
    134
    135
    136
    137
    138
    139
    140
    141
    142
    143
    144
    145
    146
    147
    148
    149
    150
    151
    152
    153
    154
    155
    156
    157
    158
    <html>
    <head>
    <title>Untitled Document</title>
    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">
    <script language="JavaScript">
    <!--
    <!--
    function MM_reloadPage(init) 
    {  //reloads the window if Nav4 resized
      if (init==true) 
      	with (navigator) 
      	{
    		if ((appName=="Netscape")&&(parseInt(appVersion)==4)) 
    		{
        		document.MM_pgW=innerWidth; 
    			document.MM_pgH=innerHeight; 
    			onresize=MM_reloadPage; 
    		}
    	}
      else if (innerWidth!=document.MM_pgW || innerHeight!=document.MM_pgH) 
      	location.reload();
    }
    MM_reloadPage(true);
    // -->
     
    function MM_findObj(n, d) { //v4.0
      var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
        d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
      if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
      for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
      if(!x && document.getElementById) x=document.getElementById(n); return x;
    }
     
    function MM_dragLayer(objName,x,hL,hT,hW,hH,toFront,dropBack,cU,cD,cL,cR,targL,targT,tol,dropJS,et,dragJS) { //v3.0
      //Copyright 1998 Macromedia, Inc. All rights reserved.
      var i,j,aLayer,retVal,curDrag=null,NS=(navigator.appName=='Netscape'), curLeft, curTop;
      if (!document.all && !document.layers) return false;
      retVal = true; if(!NS && event) event.returnValue = true;
      if (MM_dragLayer.arguments.length > 1) {
        curDrag = MM_findObj(objName); if (!curDrag) return false;
        if (!document.allLayers) { document.allLayers = new Array();
          with (document) if (NS) { for (i=0; i<layers.length; i++) allLayers[i]=layers[i];
            for (i=0; i<allLayers.length; i++) if (allLayers[i].document && allLayers[i].document.layers)
              with (allLayers[i].document) for (j=0; j<layers.length; j++) allLayers[allLayers.length]=layers[j];
          } else for (i=0;i<all.length;i++) if (all[i].style&&all[i].style.position) allLayers[allLayers.length]=all[i];}
        curDrag.MM_dragOk=true; curDrag.MM_targL=targL; curDrag.MM_targT=targT;
        curDrag.MM_tol=Math.pow(tol,2); curDrag.MM_hLeft=hL; curDrag.MM_hTop=hT;
        curDrag.MM_hWidth=hW; curDrag.MM_hHeight=hH; curDrag.MM_toFront=toFront;
        curDrag.MM_dropBack=dropBack; curDrag.MM_dropJS=dropJS;
        curDrag.MM_everyTime=et; curDrag.MM_dragJS=dragJS;
        curDrag.MM_oldZ = (NS)?curDrag.zIndex:curDrag.style.zIndex;
        curLeft= (NS)?curDrag.left:curDrag.style.pixelLeft; curDrag.MM_startL = curLeft;
        curTop = (NS)?curDrag.top:curDrag.style.pixelTop; curDrag.MM_startT = curTop;
        curDrag.MM_bL=(cL<0)?null:curLeft-cL; curDrag.MM_bT=(cU<0)?null:curTop -cU;
        curDrag.MM_bR=(cR<0)?null:curLeft+cR; curDrag.MM_bB=(cD<0)?null:curTop +cD;
        curDrag.MM_LEFTRIGHT=0; curDrag.MM_UPDOWN=0; curDrag.MM_SNAPPED=false; //use in your JS!
        document.onmousedown = MM_dragLayer; document.onmouseup = MM_dragLayer;
        if (NS) document.captureEvents(Event.MOUSEDOWN|Event.MOUSEUP);
      } else {
        var theEvent = ((NS)?objName.type:event.type);
        if (theEvent == 'mousedown') {
          var mouseX = (NS)?objName.pageX : event.clientX + document.body.scrollLeft;
          var mouseY = (NS)?objName.pageY : event.clientY + document.body.scrollTop;
          var maxDragZ=null; document.MM_maxZ = 0;
          for (i=0; i<document.allLayers.length; i++) { aLayer = document.allLayers[i];
            var aLayerZ = (NS)?aLayer.zIndex:aLayer.style.zIndex;
            if (aLayerZ > document.MM_maxZ) document.MM_maxZ = aLayerZ;
            var isVisible = (((NS)?aLayer.visibility:aLayer.style.visibility).indexOf('hid') == -1);
            if (aLayer.MM_dragOk != null && isVisible) with (aLayer) {
              var parentL=0; var parentT=0;
              if (!NS) { parentLayer = aLayer.parentElement;
                while (parentLayer != null && parentLayer.style.position) {
                  parentL += parentLayer.offsetLeft; parentT += parentLayer.offsetTop;
                  parentLayer = parentLayer.parentElement; } }
              var tmpX=mouseX-(((NS)?pageX:style.pixelLeft+parentL)+MM_hLeft);
              var tmpY=mouseY-(((NS)?pageY:style.pixelTop +parentT)+MM_hTop);
              var tmpW = MM_hWidth;  if (tmpW <= 0) tmpW += ((NS)?clip.width :offsetWidth);
              var tmpH = MM_hHeight; if (tmpH <= 0) tmpH += ((NS)?clip.height:offsetHeight);
              if ((0 <= tmpX && tmpX < tmpW && 0 <= tmpY && tmpY < tmpH) && (maxDragZ == null
                  || maxDragZ <= aLayerZ)) { curDrag = aLayer; maxDragZ = aLayerZ; } } }
          if (curDrag) {
            document.onmousemove = MM_dragLayer; if (NS) document.captureEvents(Event.MOUSEMOVE);
            curLeft = (NS)?curDrag.left:curDrag.style.pixelLeft;
            curTop = (NS)?curDrag.top:curDrag.style.pixelTop;
            MM_oldX = mouseX - curLeft; MM_oldY = mouseY - curTop;
            document.MM_curDrag = curDrag;  curDrag.MM_SNAPPED=false;
            if(curDrag.MM_toFront) {
              eval('curDrag.'+((NS)?'':'style.')+'zIndex=document.MM_maxZ+1');
              if (!curDrag.MM_dropBack) document.MM_maxZ++; }
            retVal = false; if(!NS) event.returnValue = false;
        } } else if (theEvent == 'mousemove') {
          if (document.MM_curDrag) with (document.MM_curDrag) {
            var mouseX = (NS)?objName.pageX : event.clientX + document.body.scrollLeft;
            var mouseY = (NS)?objName.pageY : event.clientY + document.body.scrollTop;
            newLeft = mouseX-MM_oldX; newTop  = mouseY-MM_oldY;
            if (MM_bL!=null) newLeft = Math.max(newLeft,MM_bL);
            if (MM_bR!=null) newLeft = Math.min(newLeft,MM_bR);
            if (MM_bT!=null) newTop  = Math.max(newTop ,MM_bT);
            if (MM_bB!=null) newTop  = Math.min(newTop ,MM_bB);
            MM_LEFTRIGHT = newLeft-MM_startL; MM_UPDOWN = newTop-MM_startT;
            if (NS) {left = newLeft; top = newTop;}
            else {style.pixelLeft = newLeft; style.pixelTop = newTop;}
            if (MM_dragJS) eval(MM_dragJS);
            retVal = false; if(!NS) event.returnValue = false;
        } } else if (theEvent == 'mouseup') {
          document.onmousemove = null;
          if (NS) document.releaseEvents(Event.MOUSEMOVE);
          if (NS) document.captureEvents(Event.MOUSEDOWN); //for mac NS
          if (document.MM_curDrag) with (document.MM_curDrag) {
            if (typeof MM_targL =='number' && typeof MM_targT == 'number' &&
                (Math.pow(MM_targL-((NS)?left:style.pixelLeft),2)+
                 Math.pow(MM_targT-((NS)?top:style.pixelTop),2))<=MM_tol) {
              if (NS) {left = MM_targL; top = MM_targT;}
              else {style.pixelLeft = MM_targL; style.pixelTop = MM_targT;}
              MM_SNAPPED = true; MM_LEFTRIGHT = MM_startL-MM_targL; MM_UPDOWN = MM_startT-MM_targT; }
            if (MM_everyTime || MM_SNAPPED) eval(MM_dropJS);
            if(MM_dropBack) {if (NS) zIndex = MM_oldZ; else style.zIndex = MM_oldZ;}
            retVal = false; if(!NS) event.returnValue = false; }
          document.MM_curDrag = null;
        }
        if (NS) document.routeEvent(objName);
      } return retVal;
    }
     
    function MM_callJS(jsStr) { //v2.0
      return eval(jsStr)
    }
    //-->
    </script>
    </head>
     
    <body bgcolor="#99CCFF" text="#000000">
     
    <div id="popup" style="position:absolute; height:400px; z-index:2; left: 14px; top: 28px; visibility: visible" onMouseDown="MM_dragLayer('popup','',0,0,0,0,true,false,-1,-1,-1,-1,false,false,0,'',false,'')"> 
      <table border="2" cellspacing="0" cellpadding="0" height="100%">
        <tr> 
          <td height="20" background="barre.gif" width="360">
            <table width="100%" border="0" cellspacing="0" cellpadding="0">
              <tr> 
                <td width="5%">&nbsp;</td>
                <td width="80%"><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="1"><b><font size="2">Microsoft 
                  - </font></b></font></td>
                <td width="5%">&nbsp;</td>
                <td width="4%">&nbsp;</td>
                <td width="6%" style="cursor:hand" onClick="MM_callJS('popup.style.visibility=\'hidden\';')">&nbsp;</td>
              </tr>
            </table>
          </td>
        </tr>
        <tr>
          <td bgcolor="#FFFFFF">&nbsp;</td>
        </tr>
      </table>
    </div>
     
     
    </body>
    </html>

  3. #3
    Inactif  
    Avatar de Kerod
    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    11 672
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 11 672
    Points : 20 778
    Points
    20 778
    Par défaut
    Super intéressant ton code !!!!!!!
    Merci

  4. #4
    Inactif  
    Avatar de Kerod
    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    11 672
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 11 672
    Points : 20 778
    Points
    20 778
    Par défaut
    Ce code est parfait mais j'arrive pas à l'adapter. En fait je voudrais le faire en javascript pur comme ce qui suit :
    Code : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    7
    8
    9
    10
    11
     
    function go(){
    document.write('<div id="popup" style="position:absolute; height:400px; z-index:2; left: 14px; top: 28px; visibility: visible" ');
    document.write('onMouseDown="MM_dragLayer(\'popup\',\'\',0,0,0,0,true,false,-1,-1,-1,-1,false,false,0,\'\',false,\'\')">');
    document.write('<table border="2" cellspacing="0" cellpadding="0" height="100%">');
    document.write('<tr><td height="20" width="360">');
    document.write('<table width="100%" border="0" cellspacing="0" cellpadding="0" border="2" style="background-color:#003366 ">');
    document.write('<tr><td width="87%" style="text-indent:5px; "><font face="Arial, Helvetica, sans-serif" color="#FFFFFF" size="1"><b>');
    document.write('<font size="2">Microsoft</font></b></font></td><td width="13%" style="cursor:pointer" onClick="MM_callJS(\'popup.style.visibility=\'hidden\';\')">fermer</td>');
    document.write('</tr></table></td></tr><tr><td bgcolor="#FFFFFF">&nbsp;</td></tr></table></div>');
    }
    problème quand je l'appel grace au onload de la page html une erreur survient et on ne peut plus bouger la fenetre... Que faire ??

  5. #5
    Inactif  
    Avatar de Kerod
    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    11 672
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 11 672
    Points : 20 778
    Points
    20 778
    Par défaut
    Vous avez aucune proposition à me faire ??

  6. #6
    Membre confirmé
    Avatar de malbaladejo
    Profil pro
    Inscrit en
    Avril 2002
    Messages
    379
    Détails du profil
    Informations personnelles :
    Âge : 46
    Localisation : France, Alpes Maritimes (Provence Alpes Côte d'Azur)

    Informations forums :
    Inscription : Avril 2002
    Messages : 379
    Points : 527
    Points
    527
    Par défaut
    Je n'ai jamais essayé d'utiliser ce code en javascript pur.
    Quel est le message d'erreur javascript ?

  7. #7
    Inactif  
    Avatar de Kerod
    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    11 672
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 11 672
    Points : 20 778
    Points
    20 778
    Par défaut
    Je pense que c'est du à l'abscence des fonctions utilisés.Car pour lui il ne trouve pas les fonctions

  8. #8
    Inactif  
    Avatar de Kerod
    Profil pro
    Inscrit en
    Septembre 2004
    Messages
    11 672
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Septembre 2004
    Messages : 11 672
    Points : 20 778
    Points
    20 778
    Par défaut
    C'est bon j'ai trouvé une autre solution que j'ai mise ici
    Merci tout de même pour ton aide

+ Répondre à la discussion
Cette discussion est résolue.

Discussions similaires

  1. "popup" avec un div
    Par laurentSc dans le forum Général JavaScript
    Réponses: 6
    Dernier message: 05/03/2013, 23h48
  2. [CS4] Problème avec Balise DIV
    Par Pierre21 dans le forum Dreamweaver
    Réponses: 2
    Dernier message: 14/06/2009, 15h47
  3. Marge avec l'utilisation de balise DIV vs Barre de defilement
    Par webtonique dans le forum Balisage (X)HTML et validation W3C
    Réponses: 1
    Dernier message: 09/01/2007, 02h43
  4. problème avec des couches de balises div
    Par pierre68314 dans le forum Général JavaScript
    Réponses: 3
    Dernier message: 06/03/2006, 16h45
  5. [W3C] Problème avec la balise div et le style "display:none&a
    Par Golork dans le forum Balisage (X)HTML et validation W3C
    Réponses: 8
    Dernier message: 14/11/2005, 20h30

Partager

Partager
  • Envoyer la discussion sur Viadeo
  • Envoyer la discussion sur Twitter
  • Envoyer la discussion sur Google
  • Envoyer la discussion sur Facebook
  • Envoyer la discussion sur Digg
  • Envoyer la discussion sur Delicious
  • Envoyer la discussion sur MySpace
  • Envoyer la discussion sur Yahoo