Visualizzazione dei risultati da 1 a 10 su 10

Hybrid View

  1. #1
    Utente di HTML.it
    Registrato dal
    Dec 2013
    Messaggi
    160
    Ti riporto lo scenario reale

    codice:
    $ tree├── index.html
    ├── resources
    │   └── example.js
    └── window-resources.js
    
    
    $ cat index.html 
    <html>
    <head>
        <script type="text/javascript" src="window-resources.js"></script>
    </head>
    <body onload="open_window_resources()">
    
    
    </body>
    </html>
    
    
    $ cat window-resources.js 
    function open_window_resources() {
        const searchParams = new URLSearchParams(window.location.search);
    
    
        var script = document.createElement("script");
        var
            day = searchParams.has('day') ? searchParams.get('day') : new Date().getDate(),
            day2Digits = String(day).padStart(2, "0")
        ;
    
    
        script.src = "resources/" + searchParams.get("config_filename") + ".js";
        script.type = "text/javascript";
        script.async = false;
    
    
        setTimeout(() => {
            document.head.appendChild(script);
        }, 0);
    
    
        url_templates.forEach(
            function (template) {
                var url = template
                    .replace("%1", day)
                    .replace("%2", day2Digits)
                ;
    
    
                window.open(url);
            }
        );
    }
    
    
    $ cat resources/example.js 
    var url_templates = new Array(
        "URL1",
        "URL2",
        "URL3",
    );
    
    
    $ xdg-open index.html?config_filename=example
    
    
    Uncaught ReferenceError: url_templates is not defined
        at open_window_resources (window-resources.js:18:5)
        at onload (index.html?config_filename=example:5:40)
    open_window_resources @ window-resources.js:18
    onload @ index.html?config_filename=example:5

  2. #2
    Moderatore di Programmazione L'avatar di alka
    Registrato dal
    Oct 2001
    residenza
    Reggio Emilia
    Messaggi
    24,482
    Quote Originariamente inviata da astros3 Visualizza il messaggio
    Ti riporto lo scenario reale
    Capisco la necessità, ma mi pare una grossa complicazione.
    Ad ogni modo, è una cosa che si può fare, quindi ci sta.

    Quote Originariamente inviata da astros3 Visualizza il messaggio
    Uncaught ReferenceError: url_templates is not defined
    at open_window_resources (window-resources.js:18:5)
    at onload (index.html?config_filename=example:5:40)
    open_window_resources @ window-resources.js:18
    onload @ index.html?config_filename=example:5
    Non hai letto attentamente la mia risposta.
    MARCO BREVEGLIERI
    Software and Web Developer, Teacher and Consultant

    Home | Blog | Delphi Podcast | Twitch | Altro...

Permessi di invio

  • Non puoi inserire discussioni
  • Non puoi inserire repliche
  • Non puoi inserire allegati
  • Non puoi modificare i tuoi messaggi
  •  
Powered by vBulletin® Version 4.2.1
Copyright © 2026 vBulletin Solutions, Inc. All rights reserved.