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 :

Question page dynamique en JS


Sujet :

JavaScript

  1. #1
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2016
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : Belgique

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2016
    Messages : 3
    Points : 1
    Points
    1
    Par défaut Question page dynamique en JS
    Bonjour,

    En fait je suis entrain de créer un petit site comme projet personnel, sur la première page l'utilisateur choisis son style de music en cliquant sur bouton.
    Par exemple lorsqu'il clique sur "Rock" la 2eme page s'ouvre et affiche du contenu par rapport a ce style de music.
    Mais ce que je n'arrive pas, c'est que le contenu de la 2eme page ne doit afficher que ce qui en rapport avec le choix de l'utilisateur.
    Est ce que je dois faire appel a AJAX en chargeant un fichier text externe ? Si vous pouvez m'aider svp ça m'aiderait vraiment.

    Merci !

  2. #2
    Membre habitué
    Homme Profil pro
    bricoleur
    Inscrit en
    Octobre 2014
    Messages
    337
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : bricoleur
    Secteur : Alimentation

    Informations forums :
    Inscription : Octobre 2014
    Messages : 337
    Points : 171
    Points
    171
    Par défaut Origine de la 2ème page
    Bonsoir

    D'où vient ta 2ème page?

    Michel

  3. #3
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2016
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : Belgique

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2016
    Messages : 3
    Points : 1
    Points
    1
    Par défaut
    Bonsoir,

    En fait je ne comprends pas trop ta question.
    Ca se présente de cette manière (cf image): la première page simple avec 3 boutons ensuite en fonction du choix de l'utilisateur on arrive sur la 2eme page et affiche quelques éléments par rapport a ce style de musique.
    Merci
    Nom : téléchargement.png
Affichages : 125
Taille : 45,1 Ko

  4. #4
    Membre habitué
    Homme Profil pro
    bricoleur
    Inscrit en
    Octobre 2014
    Messages
    337
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Oise (Picardie)

    Informations professionnelles :
    Activité : bricoleur
    Secteur : Alimentation

    Informations forums :
    Inscription : Octobre 2014
    Messages : 337
    Points : 171
    Points
    171
    Par défaut Origine de la 2ème page
    Je suppose que pour ouvrir ta 2ème page tu utilises un <href> avec son URL.
    Alors pour les autre styles de musique, tu n'as qu'à faire la même opération.
    Envoi ton code, cela sera plus facile à comprendre.

  5. #5
    Expert confirmé
    Avatar de javatwister
    Homme Profil pro
    danseur
    Inscrit en
    Août 2003
    Messages
    3 681
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : danseur

    Informations forums :
    Inscription : Août 2003
    Messages : 3 681
    Points : 5 221
    Points
    5 221
    Par défaut
    Bonjour,

    Documente-toi sur l'instruction include en php: https://www.php.net/manual/fr/function.include.php

  6. #6
    Nouveau Candidat au Club
    Homme Profil pro
    Étudiant
    Inscrit en
    Septembre 2016
    Messages
    3
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Âge : 34
    Localisation : Belgique

    Informations professionnelles :
    Activité : Étudiant

    Informations forums :
    Inscription : Septembre 2016
    Messages : 3
    Points : 1
    Points
    1
    Par défaut
    En fait je dois le faire sans php

    Je met mon code c'est un peu au brouillon encore donc désolé si c'est top niveau lisibilité.
    Pour le css j'ai pis le code de w3school qui permet de switcher de style a la volé sans rafrechir la page: https://www.w3schools.com/css/css_intro.asp

    Premiere page(index) ce qui faut regarder en fait c'est la ligne 362 où j'ai mis le code js et un peu plus bas les boutons.
    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
    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
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    <!DOCTYPE html>
    <html lang="en">
      <head>
        <style>/* Stylesheet 1: */
        body {
            font: 100% Lucida Sans, Verdana;
            margin: 20px;
            line-height: 26px;
        }
        
        .container {
            xmin-width: 900px;
        }
        
        .wrapper {
            position: relative;
            overflow: auto;
        }
        
        #top, #sidebar, #bottom, .menuitem {
            border-radius: 4px;
            margin: 4px;
        }
        
        #top {
            background-color: #4CAF50;
            color: #ffffff;
            padding: 15px;
        }
        
        #menubar {
            width: 200px;
            float: left
        }
        
        #main {
            padding: 10px;
            margin: 0 210px;
        }
        
        #sidebar {
            background-color: #32a4e7;
            color: #ffffff;
            padding: 10px;
            width: 180px;
            bottom: 0;
            top: 0;
            right: 0;
            position: absolute;
        }
        
        #bottom {
            border: 1px solid #d4d4d4;
            background-color: #f1f1f1;
            text-align: center;
            padding: 10px;
            font-size: 70%;
            line-height: 14px;
        }
        
        #top h1, #top p, #menulist {
            margin: 0;
            padding: 0;
        }
        
        .menuitem {
            background-color: #f1f1f1;
            border: 1px solid #d4d4d4;
            list-style-type: none;
            padding: 2px;
            cursor: pointer;
        }
        
        .menuitem:hover {
            background-color: #ffffff;
        }
        
        .menuitem:first-child {
           background-color:#4CAF50;
           color: white;
           font-weight:bold;
        }
        
        a {
            color: #000000;
            text-decoration: underline;
        }
        
        a:hover {
            text-decoration: none;
        }
        
        
        @media (max-width: 800px) {
            #sidebar {
                width: auto;
                position: relative;
            } 
            #main {
                margin-right: 0;
            }    
               
        }
        
        @media (max-width: 600px) {
            #menubar {
                width: auto;
                float: none;
            }
            #main {
                margin: 0;
            }    
        }
        </style>
     
        <style>/* Stylesheet 2: */
        body {
            font-family: Arial;
            background-color: #d14836;
            line-height: 20px;
        }
        
        .container {
            xmin-width: 900px;
        }
        
        .wrapper {
            position: relative;
            overflow: auto;
        }
        
        #top {
            color: #ffffff;
            padding: 15px;
            font-size: 30px;
            line-height: 26px;    
        }
        
        #top h1 {
            margin:0;
            line-height: 50px;
        }
        
        #menubar {
            width: 190px;
            float: right;
        }
        
        #main {
            padding: 10px;
            background-color: #ffffff;
            font: 80% Verdana;
        }
        
        #main h1, #main h2 {
            color: #d14836;
        }
        
        #sidebar {
            background-color: #F6DAD7;
            color: #d14836;
            padding: 10px;
        }
        
        #bottom {
            text-align: center;
            padding: 10px;
            font-size: 70%;
            color: #ffffff;
        }
        
        #menulist {
            padding:0;
            font: 16px verdana;
        }
        
        .menuitem {
            width: 155px;
            background-color: #d14836;
            border: 1px solid #d14836;
            border-radius: 40px;
            color: #ffffff;
            list-style-type: none;
            margin: 10px;
            padding: 5px;
            text-align: center;
            cursor: pointer;
        }
        
        .menuitem:nth-child(2) {
           background-color:white;
           color: #d14836;
           font-weight:bold;
        }
        
        .menuitem:hover {
            background-color: #ffffff;
            color: #d14836;
        }
        
        a {
            color: #d14836;
            text-decoration: none;
        }
        
        a:hover {
            text-decoration: underline;
        }
        </style>
     
        <style>/* Stylesheet 3: */
        body {
            font: 100% Verdana;
            margin: 20px;
            line-height: 26px;
        }
        
        .container {
            xmin-width: 900px;
        }
        
        .wrapper {
            position: relative;
            overflow: auto;
        }
        
        #sidebar {
            background-color: #f1f1f1;
            border: 1px solid #d4d4d4;
            padding-left: 10px;
        }
        
        #bottom {
            text-align: center;
            padding: 10px;
            font-size: 70%;
            line-height: 14px;
        }
        
        h1, h2, h3 {
            color: #4CAF50;
        }
        
        #menulist {
            padding: 0;
            position: relative;
            overflow: auto;
        }
        
        .menuitem {
            width: 165px;
            float: left;
            background-color: #555555;
            color: #ffffff;
            list-style-type: none;
            margin: 4px;
            padding: 2px;
            text-align: center;
            cursor: pointer;
        }
        
        .menuitem:nth-child(3) {
           background-color:#4CAF50;
        }
        
        .menuitem:hover {
            background-color: #999999;
        }
        
        a {
            color: #000000;
        }
        
        a:hover {
            color: #84c754;
        }
        </style>
        <style>/* Stylesheet 4: */
        body {
            font: 100% Courier New;
            margin: 20px;
            line-height: 26px;
            background-color: #000000;
        }
        
        .container {
            xmin-width: 900px;
        }
        
        .wrapper {
            position: relative;
            overflow: auto;
        }
        
        #top {
            color: #84c754;
            padding: 15px;
        }
        
        #main {
            padding: 10px;
            color: #84c754;
        }
        
        #sidebar {
            color: #ffffff;
            border: 1px solid #ffffff;
            border-radius: 4px;
            padding: 10px;
            width: 320px;
            top: 0;
            right: 0;
            position: absolute;
            font-size: 80%;
            line-height: 20px;
        }
        
        #bottom {
            border: 1px solid #ffffff;
            border-radius: 4px;
            color: #ffffff;
            text-align: center;
            padding: 10px;
            font-size: 70%;
            line-height: 14px;
        }
        
        #top h1,#top p {
            margin: 0;
        }
        
        .menuitem {
            color: #84c754;
            cursor: pointer;
        }
        
        .menuitem:nth-child(4) {
            color:white;
            font-weight:bold;
        }
        
        .menuitem:hover {
            color: #ffffff;
        }
        
        a {
            color: #ffffff;
        }
        
        a:hover {
            color: #84c754;
        }
        @media (max-width: 600px) {
            #sidebar {
               width: auto;
               margin-bottom:10px;        
               position: relative;
            }    
        }
        
        </style>
        <script>
            function styleMusique(index) {
              var xhttp = new XMLHttpRequest();
              xhttp.onreadystatechange = function() {
                if (this.readyState == 4 && this.status == 200) {
                  document.getElementById("genre").innerHTML =
                  this.responseText;
                }
              };
              var sUrl;
              switch(index) {
              case 1:
              sUrl = "Classique.txt";
              break;
              case 2:
              sUrl = "Metal.txt";
              break;
              case 3:
              sUrl = "Rock.txt";
              break;
              default:
              sUrl = "Classique.txt";
              } 
              xhttp.open("GET",sUrl, true);
              xhttp.send();
            }
          </script>
        </head>
        <body bis_status="ok" bis_frame_id="2468">
          <div class="container wrapper">
          <div id="top">
            <h1 >Bienvenue sur Musicmania</h1>
            <p>Veuillez selectionner votre style de musique:</p>
          </div>
          <div class="wrapper">
           <div id="menubar">
             <ul id="menulist">
               <li class="menuitem" onclick="reStyle(0)">Stylesheet 1
               </li><li class="menuitem" onclick="reStyle(1)">Stylesheet 2
               </li><li class="menuitem" onclick="reStyle(2)">Stylesheet 3
               </li><li class="menuitem" onclick="reStyle(3)">Stylesheet 4
               </li><li class="menuitem" onclick="noStyles()">No Stylesheet
             </li></ul>
            </div>
            <div id="main">
              <h1>Chaque style mérite sa propre page</h1>
              <button onclick="window.location.href = '/genreMusique.html';">Rock</button>
              <button onclick="window.location.href = '/genreMusique.html';">Metal</button>
              <button onclick="window.location.href = '/genreMusique.html';">Classique</button>
              </p>
              </p>
           </div>
            <div id="sidebar">
              <h3>Citation</h3>
              <p>La musique est partout autour de nous, il suffit juste d'écouter. August Rush</p>
            </div>
          </div>  
          .
     
     
     
          <div id="bottom">
            La musique est un art et une activité culturelle consistant à combiner sons et silences au cours du temps. Les ingrédients principaux sont le rythme (façon de combiner les sons dans le temps), la hauteur (combinaison dans les fréquences), les nuances et le timbre. Elle est aujourd'hui considérée comme une forme de poésie moderne.
            La musique donne lieu à des créations (des œuvres d'art créées par des compositeurs), des représentations. Elle utilise certaines règles ou systèmes de composition, des plus simples aux plus complexes (souvent les notes de musique, les gammes et autres). Elle peut utiliser des objets divers, le corps, la voix, mais aussi des instruments de musique spécialement conçus, et de plus en plus tous les sons (concrets, de synthèses, abstraits, etc.).
          </div>
          </div>
        <script>
        function noStyles() {
            document.styleSheets[0].disabled = true;
            document.styleSheets[1].disabled = true;
            document.styleSheets[2].disabled = true;
            document.styleSheets[3].disabled = true;
        }
        
        function reStyle(n) {
            noStyles()
            document.styleSheets[n].disabled = false;
        }
        
        function closeBlackdiv() {
            var blackdiv, stylediv;
            blackdiv = document.getElementById("blackdiv")
            blackdiv.parentNode.removeChild(blackdiv);
            stylediv = document.getElementById("stylediv")
            stylediv.parentNode.removeChild(stylediv);
        }
        
        function showStyle(n) {
        var div, text, blackdiv;
        blackdiv = document.createElement("DIV");
        blackdiv.setAttribute("style","background-color:#000000;position:absolute;width:100%;height:100%;top:0;opacity:0.5;margin-left:-20px;");
        blackdiv.setAttribute("id","blackdiv");
        blackdiv.setAttribute("onclick","closeBlackdiv()");
        document.body.appendChild(blackdiv);
        div = document.createElement("DIV");
        div.setAttribute("id","stylediv");
        div.setAttribute("style","background-color:#ffffff;padding-left:5px;position:absolute;width:auto;height:auto;top:100px;bottom:50px;left:200px;right:200px;overflow:auto;font-family: monospace; white-space: pre;line-height:16px;");
        text = document.createTextNode(document.getElementsByTagName("STYLE")[n].innerHTML);
        div.appendChild(text);
        document.body.appendChild(div);
        //alert(document.getElementsByTagName("STYLE")[n].innerHTML);
        }
        reStyle(0);
        </script>
     
     
     
        </body>
    </html>




    Seconde page:

    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
    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
    159
    160
    161
    162
    163
    164
    165
    166
    167
    168
    169
    170
    171
    172
    173
    174
    175
    176
    177
    178
    179
    180
    181
    182
    183
    184
    185
    186
    187
    188
    189
    190
    191
    192
    193
    194
    195
    196
    197
    198
    199
    200
    201
    202
    203
    204
    205
    206
    207
    208
    209
    210
    211
    212
    213
    214
    215
    216
    217
    218
    219
    220
    221
    222
    223
    224
    225
    226
    227
    228
    229
    230
    231
    232
    233
    234
    235
    236
    237
    238
    239
    240
    241
    242
    243
    244
    245
    246
    247
    248
    249
    250
    251
    252
    253
    254
    255
    256
    257
    258
    259
    260
    261
    262
    263
    264
    265
    266
    267
    268
    269
    270
    271
    272
    273
    274
    275
    276
    277
    278
    279
    280
    281
    282
    283
    284
    285
    286
    287
    288
    289
    290
    291
    292
    293
    294
    295
    296
    297
    298
    299
    300
    301
    302
    303
    304
    305
    306
    307
    308
    309
    310
    311
    312
    313
    314
    315
    316
    317
    318
    319
    320
    321
    322
    323
    324
    325
    326
    327
    328
    329
    330
    331
    332
    333
    334
    335
    336
    337
    338
    339
    340
    341
    342
    343
    344
    345
    346
    347
    348
    349
    350
    351
    352
    353
    354
    355
    356
    357
    358
    359
    360
    361
    362
    363
    364
    365
    366
    367
    368
    369
    370
    371
    372
    373
    374
    375
    376
    377
    378
    379
    380
    381
    382
    383
    384
    385
    386
    387
    388
    389
    390
    391
    392
    393
    394
    395
    396
    397
    398
    399
    400
    401
    402
    403
    404
    405
    406
    407
    408
    409
    410
    411
    412
    413
    414
    415
    416
    417
    418
    419
    420
    421
    422
    423
    424
    425
    426
    427
    428
    429
    430
    431
    432
    433
    434
    435
    436
    437
    438
    439
    440
    441
    442
    443
    444
    445
    446
    447
    448
    449
    450
    451
    452
    453
    454
    455
    456
    457
    458
    459
    460
    461
    462
    463
    464
    465
    466
    467
    468
    469
    470
    471
    472
    <!DOCTYPE html>
    <html lang="en">
      <head>
        <style>/* Stylesheet 1: */
        body {
            font: 100% Lucida Sans, Verdana;
            margin: 20px;
            line-height: 26px;
        }
        
        .container {
            xmin-width: 900px;
        }
        
        .wrapper {
            position: relative;
            overflow: auto;
        }
        
        #top, #sidebar, #bottom, .menuitem {
            border-radius: 4px;
            margin: 4px;
        }
        
        #top {
            background-color: #4CAF50;
            color: #ffffff;
            padding: 15px;
        }
        
        #menubar {
            width: 200px;
            float: left
        }
        
        #main {
            padding: 10px;
            margin: 0 210px;
        }
        
        #sidebar {
            background-color: #32a4e7;
            color: #ffffff;
            padding: 10px;
            width: 180px;
            bottom: 0;
            top: 0;
            right: 0;
            position: absolute;
        }
        
        #bottom {
            border: 1px solid #d4d4d4;
            background-color: #f1f1f1;
            text-align: center;
            padding: 10px;
            font-size: 70%;
            line-height: 14px;
        }
        
        #top h1, #top p, #menulist {
            margin: 0;
            padding: 0;
        }
        
        .menuitem {
            background-color: #f1f1f1;
            border: 1px solid #d4d4d4;
            list-style-type: none;
            padding: 2px;
            cursor: pointer;
        }
        
        .menuitem:hover {
            background-color: #ffffff;
        }
        
        .menuitem:first-child {
           background-color:#4CAF50;
           color: white;
           font-weight:bold;
        }
        
        a {
            color: #000000;
            text-decoration: underline;
        }
        
        a:hover {
            text-decoration: none;
        }
        
        
        @media (max-width: 800px) {
            #sidebar {
                width: auto;
                position: relative;
            } 
            #main {
                margin-right: 0;
            }    
               
        }
        
        @media (max-width: 600px) {
            #menubar {
                width: auto;
                float: none;
            }
            #main {
                margin: 0;
            }    
        }
        </style>
     
        <style>/* Stylesheet 2: */
        body {
            font-family: Arial;
            background-color: #d14836;
            line-height: 20px;
        }
        
        .container {
            xmin-width: 900px;
        }
        
        .wrapper {
            position: relative;
            overflow: auto;
        }
        
        #top {
            color: #ffffff;
            padding: 15px;
            font-size: 30px;
            line-height: 26px;    
        }
        
        #top h1 {
            margin:0;
            line-height: 50px;
        }
        
        #menubar {
            width: 190px;
            float: right;
        }
        
        #main {
            padding: 10px;
            background-color: #ffffff;
            font: 80% Verdana;
        }
        
        #main h1, #main h2 {
            color: #d14836;
        }
        
        #sidebar {
            background-color: #F6DAD7;
            color: #d14836;
            padding: 10px;
        }
        
        #bottom {
            text-align: center;
            padding: 10px;
            font-size: 70%;
            color: #ffffff;
        }
        
        #menulist {
            padding:0;
            font: 16px verdana;
        }
        
        .menuitem {
            width: 155px;
            background-color: #d14836;
            border: 1px solid #d14836;
            border-radius: 40px;
            color: #ffffff;
            list-style-type: none;
            margin: 10px;
            padding: 5px;
            text-align: center;
            cursor: pointer;
        }
        
        .menuitem:nth-child(2) {
           background-color:white;
           color: #d14836;
           font-weight:bold;
        }
        
        .menuitem:hover {
            background-color: #ffffff;
            color: #d14836;
        }
        
        a {
            color: #d14836;
            text-decoration: none;
        }
        
        a:hover {
            text-decoration: underline;
        }
        </style>
     
        <style>/* Stylesheet 3: */
        body {
            font: 100% Verdana;
            margin: 20px;
            line-height: 26px;
        }
        
        .container {
            xmin-width: 900px;
        }
        
        .wrapper {
            position: relative;
            overflow: auto;
        }
        
        #sidebar {
            background-color: #f1f1f1;
            border: 1px solid #d4d4d4;
            padding-left: 10px;
        }
        
        #bottom {
            text-align: center;
            padding: 10px;
            font-size: 70%;
            line-height: 14px;
        }
        
        h1, h2, h3 {
            color: #4CAF50;
        }
        
        #menulist {
            padding: 0;
            position: relative;
            overflow: auto;
        }
        
        .menuitem {
            width: 165px;
            float: left;
            background-color: #555555;
            color: #ffffff;
            list-style-type: none;
            margin: 4px;
            padding: 2px;
            text-align: center;
            cursor: pointer;
        }
        
        .menuitem:nth-child(3) {
           background-color:#4CAF50;
        }
        
        .menuitem:hover {
            background-color: #999999;
        }
        
        a {
            color: #000000;
        }
        
        a:hover {
            color: #84c754;
        }
        </style>
        <style>/* Stylesheet 4: */
        body {
            font: 100% Courier New;
            margin: 20px;
            line-height: 26px;
            background-color: #000000;
        }
        
        .container {
            xmin-width: 900px;
        }
        
        .wrapper {
            position: relative;
            overflow: auto;
        }
        
        #top {
            color: #84c754;
            padding: 15px;
        }
        
        #main {
            padding: 10px;
            color: #84c754;
        }
        
        #sidebar {
            color: #ffffff;
            border: 1px solid #ffffff;
            border-radius: 4px;
            padding: 10px;
            width: 320px;
            top: 0;
            right: 0;
            position: absolute;
            font-size: 80%;
            line-height: 20px;
        }
        
        #bottom {
            border: 1px solid #ffffff;
            border-radius: 4px;
            color: #ffffff;
            text-align: center;
            padding: 10px;
            font-size: 70%;
            line-height: 14px;
        }
        
        #top h1,#top p {
            margin: 0;
        }
        
        .menuitem {
            color: #84c754;
            cursor: pointer;
        }
        
        .menuitem:nth-child(4) {
            color:white;
            font-weight:bold;
        }
        
        .menuitem:hover {
            color: #ffffff;
        }
        
        a {
            color: #ffffff;
        }
        
        a:hover {
            color: #84c754;
        }
        @media (max-width: 600px) {
            #sidebar {
               width: auto;
               margin-bottom:10px;        
               position: relative;
            }    
        }
        </style>
        <script>
            function styleMusique(index) {
              var xhttp = new XMLHttpRequest();
              xhttp.onreadystatechange = function() {
                if (this.readyState == 4 && this.status == 200) {
                  document.getElementById("genre").innerHTML =
                  this.responseText;
                }
              };
              var sUrl;
              switch(index) {
              case 1:
              sUrl = "Classique.txt";
              break;
              case 2:
              sUrl = "Metal.txt";
              break;
              case 3:
              sUrl = "Rock.txt";
              break;
              default:
              sUrl = "Classique.txt";
              } 
              xhttp.open("GET",sUrl, true);
              xhttp.send();
            }
          </script>
        </head>
        <body bis_status="ok" bis_frame_id="2468">
          <div class="container wrapper">
          <div id="top">
            <a id="lienMain" href="/prepa/index.html"><h1>Bienvenue sur Musicmania</h1></a>
            <p>Veuillez selectionner votre style de musique:</p>
          </div>
          <div class="wrapper">
           <div id="menubar">
             <ul id="menulist">
               <li class="menuitem" onclick="reStyle(0)">Stylesheet 1
               </li><li class="menuitem" onclick="reStyle(1)">Stylesheet 2
               </li><li class="menuitem" onclick="reStyle(2)">Stylesheet 3
               </li><li class="menuitem" onclick="reStyle(3)">Stylesheet 4
               </li><li class="menuitem" onclick="noStyles()">No Stylesheet
             </li></ul>
            </div>
            <div id="main">
              <h1>Petite présentation du genre</h1>
                <p id="genre">
                  <h2></h2>
                  <button type="button" onclick="styleMusique(1)">Classique</button>
                  <button type="button" onclick="styleMusique(2)">Metal</button>
                  <button type="button" onclick="styleMusique(3)">Rock</button>
     
                </p>
              </p>
           </div>
            <div id="sidebar">
              <h3>Citation</h3>
              <p>La musique est partout autour de nous, il suffit juste d'écouter. August Rush</p>
            </div>
          </div>  
          .
     
     
     
          <div id="bottom">
            La musique est un art et une activité culturelle consistant à combiner sons et silences au cours du temps. Les ingrédients principaux sont le rythme (façon de combiner les sons dans le temps), la hauteur (combinaison dans les fréquences), les nuances et le timbre. Elle est aujourd'hui considérée comme une forme de poésie moderne.
            La musique donne lieu à des créations (des œuvres d'art créées par des compositeurs), des représentations. Elle utilise certaines règles ou systèmes de composition, des plus simples aux plus complexes (souvent les notes de musique, les gammes et autres). Elle peut utiliser des objets divers, le corps, la voix, mais aussi des instruments de musique spécialement conçus, et de plus en plus tous les sons (concrets, de synthèses, abstraits, etc.).
          </div>
          </div>
        <script>
        function noStyles() {
            document.styleSheets[0].disabled = true;
            document.styleSheets[1].disabled = true;
            document.styleSheets[2].disabled = true;
            document.styleSheets[3].disabled = true;
        }
        
        function reStyle(n) {
            noStyles()
            document.styleSheets[n].disabled = false;
        }
        
        function closeBlackdiv() {
            var blackdiv, stylediv;
            blackdiv = document.getElementById("blackdiv")
            blackdiv.parentNode.removeChild(blackdiv);
            stylediv = document.getElementById("stylediv")
            stylediv.parentNode.removeChild(stylediv);
        }
        
        function showStyle(n) {
        var div, text, blackdiv;
        blackdiv = document.createElement("DIV");
        blackdiv.setAttribute("style","background-color:#000000;position:absolute;width:100%;height:100%;top:0;opacity:0.5;margin-left:-20px;");
        blackdiv.setAttribute("id","blackdiv");
        blackdiv.setAttribute("onclick","closeBlackdiv()");
        document.body.appendChild(blackdiv);
        div = document.createElement("DIV");
        div.setAttribute("id","stylediv");
        div.setAttribute("style","background-color:#ffffff;padding-left:5px;position:absolute;width:auto;height:auto;top:100px;bottom:50px;left:200px;right:200px;overflow:auto;font-family: monospace; white-space: pre;line-height:16px;");
        text = document.createTextNode(document.getElementsByTagName("STYLE")[n].innerHTML);
        div.appendChild(text);
        document.body.appendChild(div);
        //alert(document.getElementsByTagName("STYLE")[n].innerHTML);
        }
        reStyle(0);
        </script>
     
     
     
        </body>
    </html>

  7. #7
    Invité
    Invité(e)
    Par défaut
    Bonjour,

    OK, SANS PHP...

    1- 1ère page :
    Code HTML : Sélectionner tout - Visualiser dans une fenêtre à part
    1
    2
    3
    4
    5
    6
    	<div id="main">
              <h1>Chaque style mérite sa propre page</h1>
              <button onclick="window.location.href = 'genreMusique.html?id=1';">Classique</button>
              <button onclick="window.location.href = 'genreMusique.html?id=2';">Metal</button>
              <button onclick="window.location.href = 'genreMusique.html?id=3';">Rock</button>
    	</div>

    2- 2ème page (genreMusique.html), ajouter :
    Code JavaScript : 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
    <script>
    // équivalent JS de la fonction PHP $_GET()
    function $_GET(param) {
    	var vars = {};
    	window.location.href.replace( location.hash, '' ).replace( 
    		/[?&]+([^=&]+)=?([^&]*)?/gi, // regexp
    		function( m, key, value ) { // callback
    			vars[key] = value !== undefined ? value : '';
    		}
    	);
     
    	if ( param ) {
    		return vars[param] ? vars[param] : null;	
    	}
    	return vars;
    }
     
    window.addEventListener("DOMContentLoaded", (event) => {
     
    		// Récupération style music index
    		if( $_GET('id') )
    		{
    			var index = Number($_GET('id')); // numérique
    		} else {
    			var index = 1; // défaut
    		}
     
    		styleMusique(index);
     
    });
    </script>
    Voir : Récupérer les paramètres GET d’une URL avec JavaScript
    Dernière modification par Invité ; 09/05/2020 à 18h17. Motif: Coloration syntaxique [CODE=HTML] … [/CODE]

  8. #8
    Modérateur

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

    Informations forums :
    Inscription : Janvier 2011
    Messages : 17 054
    Points : 44 568
    Points
    44 568
    Par défaut
    Bonjour,
    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    <button onclick="window.location.href = 'genreMusique.html?id=1';">Classique</button>

    Code html : Sélectionner tout - Visualiser dans une fenêtre à part
    <a href="genreMusique.html?id=1" title="Classique">Classique</a>
    me semble plus approprié !

  9. #9
    Expert confirmé
    Avatar de javatwister
    Homme Profil pro
    danseur
    Inscrit en
    Août 2003
    Messages
    3 681
    Détails du profil
    Informations personnelles :
    Sexe : Homme
    Localisation : France, Calvados (Basse Normandie)

    Informations professionnelles :
    Activité : danseur

    Informations forums :
    Inscription : Août 2003
    Messages : 3 681
    Points : 5 221
    Points
    5 221
    Par défaut
    Sinon, pour un système de switch à l'ancienne, on peut aussi faire des includes en js:

    - Une page index avec un script qui généère un fichier js en fonction du lien cliqué:

    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
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>musiques</title>
    </head>
    <body>
     
    <h1></h1>
    <div id="doc"></div>
     
    <p><a href="includesjs.htm">musique accueil</a></p>
    <p><a href="?m1">musique 1</a></p>
    <p><a href="?m2">musique 2</a></p>
    <p><a href="?m3">musique 3</a></p>
    <script>
    if(location.search){
            const scr=document.createElement("script");
            scr.src=`${location.search.slice(1)}.js`;
            document.querySelector("body").appendChild(scr);
    }
    </script>
     
    </body>
    </html>

    - des fichiers js "individualisés" pouvant contenir tous les paramètres dom + css

    http://javatwist.imingo.net/includesjs.htm

Discussions similaires

  1. Réponses: 2
    Dernier message: 14/11/2005, 16h04
  2. [CR][.Net] Mise en page dynamique Après éxecution
    Par Audrey Stelle dans le forum SAP Crystal Reports
    Réponses: 1
    Dernier message: 27/10/2005, 14h49
  3. [Tableaux] Chargement pages dynamique
    Par pittacos dans le forum Langage
    Réponses: 4
    Dernier message: 21/09/2005, 10h41
  4. [XSL-FO] gérer les sauts de pages dynamiquement ?
    Par Mrlud dans le forum XSL/XSLT/XPATH
    Réponses: 4
    Dernier message: 26/04/2005, 16h52
  5. Page dynamique
    Par BRAUKRIS dans le forum Flash
    Réponses: 12
    Dernier message: 19/09/2003, 14h28

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