Home Web Front-end JS Tutorial Analysis and solutions to refer to external js garbled code_javascript skills

Analysis and solutions to refer to external js garbled code_javascript skills

May 16, 2016 pm 05:37 PM
Garbled characters

In web development, we generally inevitably use js. We can put the js code directly in the page by using js internally. But in order to "slim down" the page, we usually put the js code externally and then reference it through src. At this time we need to pay attention to a problem: encoding problem. If the web page and js use different encodings, garbled characters will appear at this time. (You don’t need to pay attention to encoding issues when using js internally, because they use the same encoding)

For most web pages, we generally use the following two encodings: UTF-8, GB2312. So we only need to agree with the page and js encoding to solve the garbled code problem:
For GBK page reference JavaScript files encoded as UTF-8 encoding, if there is a garbled code problem, you can use the following code to solve it

Copy code The code is as follows:

<script type=”text/javascript” src=”test.js” charset=” utf-8″>

The problem of garbled JavaScript files encoded as GBK is also introduced in UTF-8 pages. You can use the following method:
Copy code The code is as follows:

<script type=”text/javascript” src=”test.js” charset=” gb2312″>

This method is used when Chinese characters appear in js files, and other characters that are prone to errors in GBK and UTF-8 encoding. For pure English is no longer needed. If it's for insurance, you can add it...
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
2 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Repo: How To Revive Teammates
4 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
Hello Kitty Island Adventure: How To Get Giant Seeds
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How to solve garbled word page numbers How to solve garbled word page numbers Jun 25, 2023 pm 03:23 PM

How to solve garbled word page numbers

How to solve Chinese garbled characters in Linux How to solve Chinese garbled characters in Linux Feb 21, 2024 am 10:48 AM

How to solve Chinese garbled characters in Linux

What to do if linux tty has Chinese garbled characters What to do if linux tty has Chinese garbled characters Mar 16, 2023 am 09:20 AM

What to do if linux tty has Chinese garbled characters

How to solve tomcat startup garbled code How to solve tomcat startup garbled code Dec 26, 2023 pm 05:21 PM

How to solve tomcat startup garbled code

How to solve the problem of Chinese garbled characters in Windows 10 How to solve the problem of Chinese garbled characters in Windows 10 Jan 16, 2024 pm 02:21 PM

How to solve the problem of Chinese garbled characters in Windows 10

How to solve the problem of garbled characters in win11 system documents How to solve the problem of garbled characters in win11 system documents Jun 29, 2023 pm 06:29 PM

How to solve the problem of garbled characters in win11 system documents

Solve the problem of garbled characters in win11 notepad Solve the problem of garbled characters in win11 notepad Jan 05, 2024 pm 03:11 PM

Solve the problem of garbled characters in win11 notepad

Editing method to solve the problem of garbled characters when opening dll files Editing method to solve the problem of garbled characters when opening dll files Jan 06, 2024 pm 07:53 PM

Editing method to solve the problem of garbled characters when opening dll files

See all articles