[php] fermeture de fenêtre (onunload)

christboy Messages postés 157 Date d'inscription   Statut Membre Dernière intervention   -  
l_epais Messages postés 140 Date d'inscription   Statut Membre Dernière intervention   -
Bonjour,
Dans mon code, ci-dessous, j'utilise la fonction onunload qui me sert a demander une confirmation de fermeture.
J'ai également sur ma page deux bouton : sauver et annuler.
Le but est que si on ne clic sur aucun bouton, onunload est apeller pour demander confirmation et si on clic sur un des deux boutons (sauver ou annuler) on quitte la page sans passer par onunload.
Est-ce possible et si oui comment ?
Merci de vos réponses.
Voici mon code avec mon idée qui ne marche pas.
  </HEAD>
<? $confirm_sortie = "oui"; ?>
<!-- -**********************************************bandeau du haut************************************************** -->
<table border='0' bordercolor='green' width="100%" cellpadding="0" cellspacing="0">
  <tr>
    <td height='28'></td>
    <td rowspan='2' valign='top' width='100%'>
      <table BORDER="0" bordercolor='yellow' CELLPADDING="0" CELLSPACING="0">
        <tr>
          <td>
            <table width='100%' CELLPADDING="0" CELLSPACING="0" background="images/bgbando.gif">
              <tr>
              <!-- bouton sauver -->
                <TD align="left">
                  <A href='#'  onclick=<? IF ($_GET['ajouter'] == 'oui' || strtolower($_SESSION['modificationDossier'])!='non') { ?>"if (confirm('Voulez-vous sauver et quitter ?')){ if(verifchp()) {  document.formulaire.submit(); document.window.unonload()="" ; <? $confirm_sortie="non";?> window.close();  } else { document.formulaire.action='dossieruser.php?ajouter=<? ECHO $_GET['ajouter'];?>&recharge=oui'; document.formulaire.submit(); document.window.unonload()= "" <? $confirm_sortie="non";?> window.close() }}"  <? } ?>
                    ; ; onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image0','','images/bouton/sauver2.gif',1)">
                    <IMG SRC="images/bouton/sauver.gif" name='Image0' border='0' ALT="" /></A></TD>
                <!-- bouton annuler -->
                <TD align="left">
                  <A href='#' onclick= " if (confirm('Voulez-vous vraiment annuler et quitter ?')){ <? $confirm_sortie="non";?> window.close()}"; onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image1','','images/bouton/annuler2.gif',1)">
                    <IMG SRC="images/bouton/annuler.gif" name='Image1' border='0' ALT="" /></A></TD>
                <!-- bouton aide (désactivé) -->
                <td align="left" <? if(strtolower($_SESSION['UtilisationBDC'])=='non') echo "style='display:none'"; ?>
                  <a href="#" onclick="hauteur=screen.height-10;largeur=screen.width-10;window.open('bdcuser.php','','width='+largeur+',height='+hauteur+',top=0,left=0,menubar=no,directories=no, location=no, toolbar=no,scrollbars=yes,resizable=yes')"; onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image3','','images/bouton/boutonbdc2.gif',1)">
                    <IMG SRC="images/bouton/boutonbdc.gif" name='Image3' border='0' ALT="" /></a></td>
                <!-- nom utilisateur -->
                <td align="left" width='100%'>
            <?
						$sql = "select * from tblUsersSite where Rédacteur like '$_SESSION[loginuser]'";
						$result = $db->query($sql);
						$row =& $result->fetchRow(DB_FETCHMODE_ASSOC);
						echo "<div class='bonjour'>Connexion : ".$row[majBDD('Prénom')]." ".$row[majBDD('Nom')]."</div>";
						//$db->disconnect();
            ?>
            </td>
              </tr>
            </table></td>
        </tr>
        <tr HEIGHT="0">
          <td>
            <TABLE BORDER="0" bordercolor='red' CELLPADDING="0" CELLSPACING="0" HEIGHT="0">
              <tr>
                <TD WIDTH="1000" HEIGHT="0">
                  <table width='100%' CELLPADDING="0" CELLSPACING="0">
                    <div class='barrefiltre'>
                  </table></td>
              </tr>
            </table></td>
        </tr>
      </table></td>
  </tr>
</table>
<!-- ********************************************** FIN bandeau du haut************************************************** -->
<BODY LEFTMARGIN="0" TOPMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0" <?if($confirm_sortie=="oui"){?> onBeforeUnload=" if (verifchp()) { if (confirm('Voulez-vous enregistrer le dossier ?')) document.formulaire.submit(); } else {  if (confirm('Voulez-vous continuer Ó saisir l\'incident ?')) { document.formulaire.action='dossieruser.php?ajouter=<? echo $_GET['ajouter'];?>&recharge=oui'; document.formulaire.submit(); } }<?}?>">
    <form method="POST" target='<? echo $n_dossier; ?>' action='enreg_dossieruser.php?ajouter=<? echo $_GET['ajouter']; ?> ' name="formulaire">

      <table width="100%" height='100%' border='0' bordercolor='blue' cellpadding="0" cellspacing="0">
        <tr>
          <td background="images/bgband2.gif" valign=top>
            <!--********************************************** partie haute ********************************************************-->
            <table width="100%" border='0' bordercolor='blue' cellpadding="0" cellspacing="0" height=<? echo $_SESSION['TailleSaisieIncident']; ?>>
              <tr>
                <td valign=top>
                  <div style='position: relative'>
                    <input type='hidden' name='n_dossier' value='<? echo $n_dossier; ?>'>
A voir également:

2 réponses

christboy Messages postés 157 Date d'inscription   Statut Membre Dernière intervention   20
 
Vu que dans ce site le code est illisible je vais vous mettre les trois choses importantes ^^':
-bouton sauver:
<A href='#'  onclick=<? IF ($_GET['ajouter'] == 'oui' || strtolower($_SESSION['modificationDossier'])!='non') { ?>"if (confirm('Voulez-vous sauver et quitter ?')){ if(verifchp()) {  document.formulaire.submit(); document.window.unonload()="" ; <? $confirm_sortie="non";?> window.close();  } else { document.formulaire.action='dossieruser.php?ajouter=<? ECHO $_GET['ajouter'];?>&recharge=oui'; document.formulaire.submit(); document.window.unonload()= "" <? $confirm_sortie="non";?> window.close() }}"  <? } ?>
                    ; ; onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image0','','images/bouton/sauver2.gif',1)">
                    <IMG SRC="images/bouton/sauver.gif" name='Image0' border='0' ALT="" /></A>



-bouton annuler :
<A href='#' onclick= " if (confirm('Voulez-vous vraiment annuler et quitter ?')){ <? $confirm_sortie="non";?> window.close()}"; onMouseOut="MM_swapImgRestore()" onMouseOver="MM_swapImage('Image1','','images/bouton/annuler2.gif',1)">
                    <IMG SRC="images/bouton/annuler.gif" name='Image1' border='0' ALT="" /></A>


et enfin la balise body qui ne fonction pas comme je voudrait ^^':
<BODY LEFTMARGIN="0" TOPMARGIN="0" MARGINWIDTH="0" MARGINHEIGHT="0" <?if($confirm_sortie=="oui"){?> onBeforeUnload=" if (verifchp()) { if (confirm('Voulez-vous enregistrer le dossier ?')) document.formulaire.submit(); } else {  if (confirm('Voulez-vous continuer Ó saisir l\'incident ?')) { document.formulaire.action='dossieruser.php?ajouter=<? echo $_GET['ajouter'];?>&recharge=oui'; document.formulaire.submit(); } }<?}?>">


NOTE: le $confirm_sortie est la variable servant a déterminer si on ou non il faut passer par la methode onunload.
-1
christboy Messages postés 157 Date d'inscription   Statut Membre Dernière intervention   20
 
up je suis vraiment coincer ><
0
l_epais Messages postés 140 Date d'inscription   Statut Membre Dernière intervention   31
 
onbeforeunload
-3