Vdelajte JavaScript v HTML - evo kako
Zunanji JavaScript lahko preprosto vključite v HTML. Tukaj vam prikazujemo različne možnosti.
Vdelajte JavaScript neposredno na strani HTML
Najbolje je, da se skript drži v glavi, tako da se vaša stran in drugi skripti naložijo čim hitreje.
- Če želite vstaviti JavaScript v HTML 5, je vnos med temi oznakami postavljen v območje "XXXX" XXXX.
- Če uporabljate starejšo različico HTML, je skript videti tako: XXXX.
- Za obiskovalce vašega spletnega mesta, ki niso aktivirali JavaScript, lahko z "noscript" določite besedilo, ki je prikazano namesto JavaScript.
- Celoten ukaz potem izgleda tako: XXXXZa odpiranje strani aktivirajte JavaScript
- Če je skript potreben na drugih straneh HTML, ga morate vnesti na ustrezne posamezne strani in na vsaki posamezni strani narediti spremembe.
Vdelajte JavaScript kot zunanjo datoteko v strani HTML
Če imate skript v datoteki s pripono .js, jo lahko vdelate v področje glave svoje strani na naslednji način:
- Za HTML5 je to dovolj:.
- Za starejšo različico HTML uporabite to varianto :.
- Prenesite datoteko .js na vaš spletni strežnik s programom FTP.
- Velika prednost datoteke JavaScript je, da lahko vse strani dostopajo do funkcij JavaScript takoj, ko je povezava vstavljena v glavo ustreznega spletnega mesta.
- Spremembe so nato potrebne le v datoteki .js in ne več na vsaki posamezni strani.
V naslednjem praktičnem nasvetu bomo razložili, kako lahko integrirate JavaScript v WordPress.