Get the App
SLTechnology News&Howtos  ›  Development  › 

The solution to the compatibility of JS script

Shulou Source: shulou.com Published: 2022-06-02 10:47:25 11月16日 Update

This article introduces you the solution to the compatibility problem of JS script, the content is very detailed, interested friends can refer to, hope to be helpful to you.

Here are a few tips for solving JS script compatibility. The first question we should consider about JS script compatibility should be whether the running platform supports client script. It is common practice to include the script body in a HTML comment.

A few tips for solving the compatibility of JS scripts

Where there is JS scripting compatibility, the solution is to use different features for different platforms or use alternative methods, which is the best policy; but there are times when we can't solve the problem with the above method, we can see if the problem is serious, if not, then we can ignore it.

1. Use HTML to comment out the script

One of the questions we should consider about JS script compatibility is whether the running platform supports client script. A common practice is to include the script body in a HTML comment:

Browsers that do not support JS scripts ignore the and tags and treat other code as a HTML comment, while browsers that support scripts comment one-line with "/ /".

two。 Characteristics, platform detection

When the feature we want to use is related to the platform, we have to test it first and then use it. There are two ways of detection: one is to directly detect whether the platform supports the feature, and the other is to test the platform type and then use the corresponding feature. The code is as follows:

3. Substitute? ignore? Stop it?

For places where there is JS script compatibility, the solution is to use different features or alternative methods for different platforms, this is the best policy; but there are times when we can't solve the problem with the above methods, we can see if the problem is serious, if not, then we can ignore it. For example, a feature is invalid on Netscape2, but now basically no one uses Netscape2, so we ignore it. If it can't be solved but the problem is serious, then we should stop running the script and tell the user exactly what happened!

This is the end of the solution to the compatibility problem of JS scripts. I hope the above content can be helpful to you and learn more knowledge. If you think the article is good, you can share it for more people to see.

Tags: Scripts methods problems platforms features compatibility comments support detection differences runs best policies subjects code practices content places customers clients skills Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno OPPO Reno macOS Shulou Information vpn Shulou Tech Info