简体   繁体   中英

How can I detect and warn the user when Javascript is disabled?

Websites can use the <noscript> tag to degrade gracefully (or warn the user) when their browser does not support or execute Javascript. However, some add-ons (eg, NoScript, uMatrix) allow users to disable third-party Javascript, ie, Javascript from the same website will run but Javascript served from other domains will not. This is a sensible thing to do for privacy and security concerns. However, it needs to be detected and handled for websites that crucially depend on third-party Javascript (eg, Javascript libraries retrieved from a third-party CDN).

How can I detect and warn users when their browser is blocking third-party Javascript? Obviously I could do this by putting specific Javascript on another domain that I control, and testing whether it runs or not with Javascript on the main domain. However, this is cumbersome (need to manage another domain, etc.). Is there a simpler and cleaner solution?

Just a guess, don't judge, can't you just do something like this

In case of jquery

if (typeof(jQuery) !== undefined)
{
//do something
}

So if the lib is not there just make a fallback

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM