Javascript 简明教程

Enabling JavaScript in Browsers

Enabling JavaScript

所有现代浏览器都内置支持 JavaScript,并且默认情况下已启用 JavaScript。通常,你可能需要手动启用或禁用此支持。本章将说明如何在浏览器中启用和禁用 JavaScript 支持:Chrome、Microsoft Edge、Firefox、Safari 和 Opera。

All modern browsers come with built-in support for JavaScript, and it has enabled JavaScript by default. Frequently, you may need to enable or disable this support manually. This chapter explains how to turn JavaScript support on and off in your browsers: Chrome, Microsoft Edge, Firefox, Safari, and Opera.

JavaScript in Chrome

以下是打开或关闭 Chrome 中 JavaScript 的步骤 −

Here are the steps to turn on or turn off JavaScript in Chrome −

  1. Click the Chrome menu at the top right-hand corner of your browser.

  2. Select the Settings option.

  3. Click on the Privacy and Security tab from the left sidebar.

  4. Click Show advanced settings at the end of the page.

  5. Next, click on the Site Settings tab.

  6. Now, scroll to the bottom of the page, and find the content section. Click on the JavaScript tab in the content section.

  7. Here, you can select a radio button to turn JavaScript on or off.

此外,你还可以添加自定义网站的 URL,以在特定网站上阻止和取消阻止 JavaScript。

Also, you can add the URLS of the custom website to block and unblock JavaScript on particular websites.

JavaScript in Microsoft Edge

以下是在 Microsoft Edge 中启用或禁用 JavaScript 的简单步骤:

Here are simple steps to turn on or turn off JavaScript in your Microsoft Edge −

  1. Click Edge menu (three dots) at top right-hand corner of the edge browser.

  2. Follow More Tools → Internet Options from the menu.

  3. Select Security tab from the dialog box.

  4. Click the Custom Level button.

  5. Scroll down till you find Scripting option.

  6. Select Enable radio button under Active scripting.

  7. Finally click OK and come out.

要禁用 Microsoft Edge 中的 JavaScript 支持,需要选择“活动脚本”下的“禁用”单选按钮。

To disable JavaScript support in your Microsoft Edge, you need to select Disable radio button under Active scripting.

JavaScript in Firefox

以下是打开或关闭 Firefox 中 JavaScript 的步骤 −

Here are the steps to turn on or turn off JavaScript in Firefox −

  1. Open a new tab → type about: config in the address bar.

  2. Then you will find the warning dialog. Select I’ll be careful, I promise!

  3. Then you will find the list of configure options in the browser.

  4. In the search bar, type javascript.enabled.

  5. There you will find the option to enable or disable javascript by right-clicking on the value of that option → select toggle.

  6. If javascript.enabled is true, it converts to false upon clicking toggle. If javascript is disabled, it gets enabled upon clicking toggle.

JavaScript in Safari

当您安装 Safari 网络浏览器时,默认情况下会安装 JavaScript。如果您已禁用它并且希望启用,请按照以下步骤操作。

When you install the Safari web browser, JavaScript comes installed by default. If you have disabled it and want to enable it, follow the steps below.

  1. Click on the safari menu from the top-left corner.

  2. Select the preferences in the dropdown menu. It will open a new window.

  3. Open the security tab.

  4. Check the Enable JavaScript checkbox in the ‘web content’ section to enable the javascript. You can disable the JavaScript by unchecking the checkbox.

  5. Now, close the preference window and reload the web page.

JavaScript in Opera

以下是打开或关闭 Opera 中 JavaScript 的步骤 −

Here are the steps to turn on or turn off JavaScript in Opera −

  1. Follow Tools → Preferences from the menu.

  2. Select the Advanced option from the dialog box.

  3. Select Content from the listed items.

  4. Select Enable JavaScript checkbox.

  5. Finally, click OK and come out.

要禁用 Opera 中的 JavaScript 支持,不应选择 enable JavaScript checkbox

To disable JavaScript support in your Opera, you should not select the enable JavaScript checkbox.

JavaScript in Brave

Brave 以其安全性和隐私性而闻名。因此,它不允许我们永久禁用 JavaScript,但我们可以通过以下步骤为特定网站禁用 JavaScript。

The Brave is well-known for its security and privacy. So, It doesn’t allow us to disable the JavaScript permanently, but we can disable the JavaScript for the particular website by following the below steps.

  1. Open the website URL to disable the browser for it.

  2. Now, Click on the ‘Brave Shields’ icon in the address bar.

  3. Find the Scripts option in the Shields panel.

  4. The default value of the Scripts is “Allow Scripts”. If you want to disable JavaScript, choose the "Block Scripts" option.

Warning for Non-JavaScript Browsers

如果你必须使用 JavaScript 进行一些重要操作,那么可以使用 <noscript> 标记向用户显示一条警告消息。

If you have to do something important using JavaScript, then you can display a warning message to the user using <noscript> tags.

你可以像下面那样在脚本块之后立即添加一个 noscript 块:

You can add a noscript block immediately after the script block as follows −

<html>
<head>
   <script>
      document.write("Hello World!")
   </script>

   <noscript>
	  Sorry...JavaScript is needed to go ahead.
   </noscript>
</head>
<body>
</body>
</html>

现在,如果用户的浏览器不支持 JavaScript 或 JavaScript 未启用,那么 </noscript> 中的信息会显示在屏幕上。

Now, if the user’s browser does not support JavaScript or JavaScript is not enabled, then the message from </noscript> will be displayed on the screen.