Incorpora JavaScript in HTML - Ecco come
Puoi facilmente integrare JavaScript esterno in HTML. Ti mostriamo le diverse opzioni qui.
Incorpora JavaScript direttamente nelle pagine HTML
È meglio tenere lo script in testa in modo che la tua pagina e altri script vengano caricati il più rapidamente possibile.
- Per inserire JavaScript in HTML 5, la voce tra questi tag viene posizionata nell'area XXXX "XXXX".
- Se si utilizza una versione HTML precedente, lo script è simile al seguente: XXXX.
- Per i visitatori del tuo sito che non hanno attivato JavaScript, puoi utilizzare "noscript" per specificare un testo che viene visualizzato al posto di JavaScript.
- L'intero comando si presenta così: XXXXSi prega di attivare JavaScript per aprire la pagina
- Se lo script è richiesto su altre pagine HTML, è necessario inserirlo nelle singole pagine corrispondenti e apportare modifiche su ogni singola pagina.
Incorpora JavaScript come file esterno in pagine HTML
Se lo script è presente in un file con estensione .js, è possibile incorporarlo nell'area dell'intestazione della pagina nel modo seguente:
- Per HTML5 questo è sufficiente:
- Per una versione HTML precedente, utilizzare questa variante :.
- Trasferisci il file .js sul tuo server web usando un programma FTP.
- Il grande vantaggio di un file JavaScript è che tutte le pagine possono accedere alle funzioni JavaScript non appena il collegamento è stato inserito nella testa del rispettivo sito Web.
- Le modifiche sono quindi necessarie solo nel file .js e non più su ogni singola pagina.
Nel prossimo consiglio pratico spiegheremo come integrare JavaScript in WordPress.