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

jQuery Discussion :

Modif d'un script pour demarrage automatiquement


Sujet :

jQuery

  1. #1
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    89
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2005
    Messages : 89
    Points : 46
    Points
    46
    Par défaut Modif d'un script pour demarrage automatiquement
    Bonjour,

    J'ai trouvé ce bout de code pour afficher une info tout au début de mon site.
    Mais sauf que ce code ne 'sexecute qui si l'on clique.
    Comment modifier ce code pour qu'il s'execute automatiquement sur ma page d'index.

    Merci pour votre aide précieuse.

    Cordialement.


    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
    <!DOCTYPE html>
    <html>
    <head>
      <title>Modal Dialog Windows Using Javascript and CSS</title>
      <style>
        .blockbkg {
          background-color: black;
          opacity: 90%;
          filter:alpha(opacity=90);
          background-color: rgba(0,0,0,0.90);
          width: 100%;
          min-height: 100%;
          overflow: hidden;
          float: absolute;
          position: fixed;
          top: 0;
          left: 0;
          color: white;
        }
        .cont {
          background-color: white;
          color: black;
          font-size: 16px;
          border: 1px solid gray;
          padding: 20px;
          display:block;
          position: absolute;
          top: 10%;
          left: 35%;
          width: 400px;
          height: 400px;
          overflow-y: scroll;
        }
        .closebtn {
          width: 20px;
          height: 20px;
          padding: 5px;
          margin: 2px;
          float: right;
          top: 0;
          background-image: url(x.png);
          background-repeat: no-repeat;
          background-position:center;
          background-color: lightgray;
          display: block;
        }
        .closebtn:hover {
          cursor: pointer;
        }
        .normal {
          background-color: lightblue;
          width: 900px;
          min-height: 200px;
          padding: 20px;
        }
      </style>
      <script src="//ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js" type="text/javascript">
      </script>
     
      <script>
        $(document).ready(function () {
          $("#closebtn").click(function () {
            $("#dlg").hide('800', "swing", function () { $("#bkg").fadeOut("500"); });
          });
          $("#opn").click(function () {
            if (document.getElementById('bkg').style.visibility == 'hidden') {
              document.getElementById('bkg').style.visibility = '';
              $("#bkg").hide();
            }
            if (document.getElementById('dlg').style.visibility == 'hidden') {
              document.getElementById('dlg').style.visibility = '';
              $("#dlg").hide();
            }
            $("#bkg").fadeIn(500, "linear", function () { $("#dlg").show(800, "swing"); });
          });    
     
        });
      </script>
    </head>
     
    <body>
      <div class="normal">
        <h1>Modal Dialogs</h1>
        <p>
          This is an example of how to create <strong>modal dialog popup windows</strong> for
          your pages using javascript and CSS. Modal dialog popups are better than window-based
          popups, because a new browser window is not required and the user does not have to leave
          the page. This is great for when you need an easy way for the user to carry out a specific
          action on the same page and control the modality of the window.
        </p>
        <p><a href="#" id="opn">Click here</a> to display the javascript modal popup dialog!</p>
      </div>
     
      <div class="blockbkg" id="bkg" style="visibility: hidden;">
        <div class="cont" id="dlg" style="visibility: hidden;">
          <div class="closebtn" title="Close" id="closebtn"></div>
          <h1>Hello World!</h1>
          <p>
            This is a neat little trick to get a modal popup dialog box in your web pages
            without disturbing the user experience or dsitracting them with popup windows or
            new tabs...
          </p>
          <p>
            The <strong>popup dialog</strong> uses javascript (jQuery) and CSS to create a modal dialog that
            will retain focus over the parent window until it is closed. The trick is simple.
            We use block-elements (divs) to create the dialog window. The CSS rules for <em>position</em>,
            <em>float</em>, <em>top</em>, <em>left</em>/<em>right</em>, and <em>opacity</em> (or CSS3
            transparency) allows us to create a semi-transparent div over the entire page, thereby creating
            the illusion of modalness. The other div then takes focus over the center of the window.
          </p>
          <img src="https://sheriframadan.com/examples/uploadit/uploads/50f00e1434e8b.jpg" width="200" height="252">
          <p>
            We can also retain content view control over the modal dialog with the <em>overflow</em> CSS property.
            This means no matter what we place inside of our dialog window the content will remain inside
            of the defined bounds even if scrolling becomes necessary within the div.
          </p>
        </div>
      </div>
    </body>
    </html>

  2. #2
    Rédacteur/Modérateur

    Avatar de SpaceFrog
    Homme Profil pro
    Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Inscrit en
    Mars 2002
    Messages
    39 637
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 74
    Localisation : Royaume-Uni

    Informations professionnelles :
    Activité : Développeur Web Php Mysql Html Javascript CSS Apache - Intégrateur - Bidouilleur SharePoint
    Secteur : Industrie

    Informations forums :
    Inscription : Mars 2002
    Messages : 39 637
    Points : 66 661
    Points
    66 661
    Billets dans le blog
    1
    Par défaut
    regarde du coté de trigger() qui te permettra de lancer le click ...
    Ma page Developpez - Mon Blog Developpez
    Président du CCMPTP (Comité Contre le Mot "Problème" dans les Titres de Posts)
    Deux règles du succès: 1) Ne communiquez jamais à quelqu'un tout votre savoir...
    Votre post est résolu ? Alors n'oubliez pas le Tag

    Venez sur le Chat de Développez !

  3. #3
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    89
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2005
    Messages : 89
    Points : 46
    Points
    46
    Par défaut
    re,

    J'ai modifié le script avec la fonction trigger. Mais cela ne fonctionne pas.

    Y a t-il quelqu'un pour me corriger le script.
    Merci pour l'aide.

    Cordialement
    Code html : 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
    <!DOCTYPE html>
    <html>
    <head>
      <title>Modal Dialog Windows Using Javascript and CSS</title>
      <style>
        .blockbkg {
          background-color: black;
          opacity: 90%;
          filter:alpha(opacity=90);
          background-color: rgba(0,0,0,0.90);
          width: 100%;
          min-height: 100%;
          overflow: hidden;
          float: absolute;
          position: fixed;
          top: 0;
          left: 0;
          color: white;
        }
        .cont {
          background-color: white;
          color: black;
          font-size: 16px;
          border: 1px solid gray;
          padding: 20px;
          display:block;
          position: absolute;
          top: 10%;
          left: 35%;
          width: 400px;
          height: 400px;
          <? //overflow-y: scroll; ?>
        }
        .closebtn {
          width: 20px;
          height: 20px;
          padding: 5px;
          margin: 2px;
          float: right;
          top: 0;
          background-image: url(x.png);
          background-repeat: no-repeat;
          background-position:center;
          background-color: lightgray;
          display: block;
        }
        .closebtn:hover {
          cursor: pointer;
        }
        .normal {
          background-color: lightblue;
          width: 900px;
          min-height: 200px;
          padding: 20px;
        }
      </style>
      <script src="jquery.min.js" type="text/javascript">
      </script>
      <script>
        $(document).ready(function () 
            {
                      $("#closebtn").click(function () 
                      {
                            $("#dlg").hide('800', "swing", function () { $("#bkg").fadeOut("500"); });
                      });
                      
                      $("#opn").click(function () 
                      {
                                    if (document.getElementById('bkg').style.visibility == 'hidden') 
                                    {
                                      document.getElementById('bkg').style.visibility = '';
                                      $("#bkg").hide();
                                    }
                            
                                    if (document.getElementById('dlg').style.visibility == 'hidden') 
                                    {
                                      document.getElementById('dlg').style.visibility = '';
                                      $("#dlg").hide();
                                    }
                            $("#bkg").fadeIn(500, "linear", function () { $("#dlg").show(800, "swing"); });
                      });    
     
        }).trigger("click");
            
      </script>
    </head>
     
    <body>
      <div class="blockbkg" id="bkg" style="visibility: hidden;">
        <div class="cont" id="dlg" style="visibility: hidden;">
          <h1>Hello World!</h1>
          <p>
            This is a neat little trick to get a modal popup dialog box in your web pages
            without disturbing the user experience or dsitracting them with popup windows or
            new tabs...
          </p>
          <p>
            The <strong>popup dialog</strong> uses javascript (jQuery) and CSS to create a modal dialog that
            will retain focus over the parent window until it is closed. The trick is simple.
            We use block-elements (divs) to create the dialog window. The CSS rules for <em>position</em>,
            <em>float</em>, <em>top</em>, <em>left</em>/<em>right</em>, and <em>opacity</em> (or CSS3
            transparency) allows us to create a semi-transparent div over the entire page, thereby creating
            the illusion of modalness. The other div then takes focus over the center of the window.
          </p>
     
        </div>
      </div>
     
     
     
    </body>
    </html>

  4. #4
    Modérateur

    Avatar de NoSmoking
    Homme Profil pro
    Inscrit en
    Janvier 2011
    Messages
    16 959
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations forums :
    Inscription : Janvier 2011
    Messages : 16 959
    Points : 44 122
    Points
    44 122
    Par défaut
    Bonjour,
    mettre un trigger("click") sur $(document).ready n'a pas grand sens.

    Ne serait ce pas plutôt sur $(#opn) qu'il faudrait l'appliquer ?

  5. #5
    Membre du Club
    Profil pro
    Inscrit en
    Octobre 2005
    Messages
    89
    Détails du profil
    Informations personnelles :
    Localisation : France

    Informations forums :
    Inscription : Octobre 2005
    Messages : 89
    Points : 46
    Points
    46
    Par défaut
    merci pour ta réponse mais même en modifiant comme cela ça ne marche pas non plus

    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
      <script>
        $(document).ready(function () 
    	{
    		  $("#closebtn").click(function () 
    		  {
    			$("#dlg").hide('800', "swing", function () { $("#bkg").fadeOut("500"); });
    		  });
     
    		  $("#opn").click(function () 
    		  {
    				if (document.getElementById('bkg').style.visibility == 'hidden') 
    				{
    				  document.getElementById('bkg').style.visibility = '';
    				  $("#bkg").hide();
    				}
     
    				if (document.getElementById('dlg').style.visibility == 'hidden') 
    				{
    				  document.getElementById('dlg').style.visibility = '';
    				  $("#dlg").hide();
    				}
    			$("#bkg").fadeIn(500, "linear", function () { $("#dlg").show(800, "swing"); });
    		  }).trigger("click");    
     
        });
     
      </script>
    et pas non plus avec ce script

    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
      <script>
        $(document).ready(function () 
    	{
    		  $("#closebtn").click(function () 
    		  {
    			$("#dlg").hide('800', "swing", function () { $("#bkg").fadeOut("500"); });
    		  });
     
    		  $("#opn").click(function () 
    		  {
    				if (document.getElementById('bkg').style.visibility == 'hidden') 
    				{
    				  document.getElementById('bkg').style.visibility = '';
    				  $("#bkg").hide();
    				}
     
    				if (document.getElementById('dlg').style.visibility == 'hidden') 
    				{
    				  document.getElementById('dlg').style.visibility = '';
    				  $("#dlg").hide();
    				}
    			$("#bkg").fadeIn(500, "linear", function () { $("#dlg").show(800, "swing"); });
    		  }); 
    		  $( "#opn" ).trigger( "click" );   
     
        });
     
      </script>
    merci pour votre aide

  6. #6
    Modérateur

    Avatar de NoSmoking
    Homme Profil pro
    Inscrit en
    Janvier 2011
    Messages
    16 959
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Isère (Rhône Alpes)

    Informations forums :
    Inscription : Janvier 2011
    Messages : 16 959
    Points : 44 122
    Points
    44 122
    Par défaut
    aucune raison que cela ne fonctionne pas, peut être une erreur ailleurs.

    Ne fonctionne pas ... plus de détails peut être

  7. #7
    Membre expérimenté Avatar de Lorenzo77
    Profil pro
    Inscrit en
    Mai 2006
    Messages
    1 472
    Détails du profil
    Informations personnelles :
    Âge : 52
    Localisation : France, Paris (Île de France)

    Informations forums :
    Inscription : Mai 2006
    Messages : 1 472
    Points : 1 537
    Points
    1 537
    Par défaut
    salut,

    3 soluces :


    http://jsfiddle.net/LorenzoFR/S7Sjx/
    http://jsfiddle.net/LorenzoFR/TvWbD/


    par contre si tu veux que le lien reste actif pour que l'utilisateur puisse ouvrir plusieurs fois la popup, alors vire les () et rajoute ton "trigger click" comme indiqué précédemment (oui, ca fonctionne ) :
    http://jsfiddle.net/LorenzoFR/S7Sjx/6/
    Le plus grand arbre est né d'une graine menue, une tour de neuf étages est partie d'une poignée de terre.
    Mon blog : http://web.codeur.free.fr

Discussions similaires

  1. Script pour entrer automatiquement un login et mdp
    Par boboss76 dans le forum VBScript
    Réponses: 6
    Dernier message: 16/01/2012, 22h07
  2. script pour suppression automatique
    Par bganata dans le forum VBScript
    Réponses: 5
    Dernier message: 01/04/2010, 09h18
  3. petit script pour vote automatiques
    Par intoxxx dans le forum Scripts/Batch
    Réponses: 1
    Dernier message: 16/11/2009, 13h43
  4. Réponses: 2
    Dernier message: 02/06/2009, 13h43
  5. Script de demarrage automatique d'une instance Oracle 9i sous Linux
    Par redabadache3 dans le forum Administration
    Réponses: 1
    Dernier message: 23/01/2008, 16h30

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