Disable part of the page JavaScript is not all but part, page javascript

Source: Internet
Author: User

Disable part of the page JavaScript is not all but part, page javascript

The methods discussed in this article have not been applied in actual projects, because I have not met projects that require such a purpose, but the experiment shows that it is feasible.

I. Sources of my ideas

The appearance of JavaScipt is a good thing that makes webpage pages more lively. Of course, the benefits are not just that, in recent years, the booming AJAX applications have attracted more attention to the application of JavaScipt (some programmers do not regard it as a language, most of which are the title of a script, or even look down on people who engage in scripts. Currently, script permissions are available on the official websites of some blogs, allowing users to customize scripts to enrich their own space, especially some technical blogs that provide a quite loose development environment. However, we also find that some blogs impose restrictions on some script methods. Note: I am talking about some restrictions here. If it is all restrictions, it is very easy to simply filter out the <script> script block, but how are some restrictions implemented?

I have not encountered such a problem in my previous project, so I have not done much in-depth research. At first, I just thought of using the "replace" method. Obviously, this method does not work because it may cause errors. For example, if I want to disable the alert method, the following code is available:
Window. alert ('some message ');

Now we need to invalidate the above Code. Just change alert. For example, if we change it to uppercase ALERT, a script error will certainly be reported, however, you can still use try {} catch {} to include ALERT. However, this recognition of the banned language package is a major problem, and there will be such an error: the document. write ('alert some message'); alert is also replaced.

Later I thought of method rewriting, rewriting the method to be disabled, and letting it do nothing. The results prove to be true, but I don't know if it is a scientific method, I will discuss it with you.

II. Specific implementation

Let's take a look at the following code to disable the "alert" and "write" methods:

window.alert=function(){}document.write=function(){}window.alert('Alert some message');document.write('Write some message');

It looks really simple. In actual application, extract the first two lines and store them in an external JS file, load the JS file on the page where the JavaScript method needs to be filtered (you can also load the script in the first line of the content block that the user edits, in this way, our administrator or Web Page Maker can still use the method to be disabled in the previous HTML block. In this way, calling the disabled method will not work.

Note: At last, some DOM operation methods should be disabled, such as the remove () method, because you can use the DOM operation method to remove the JS file you loaded at the beginning.


How to enable firefox to disable JavaScript on a specific page

Yesscript extension can be addons.mozilla.org/zh-cn/firefox/addon/4102/
After installation, click the yesscript button and add the address for Disabling javascript to the filter list. noscript is used to disable javascript on all pages first, and then enable some pages based on the whitelist set by the user. the opposite of your requirements is not suitable for you

It is often said that when a webpage is used, how large is the user base for Disabling javascript?

Currently, all browsers support javaScript. Basically, all webpages use javaScript. Disabling javaScript is rarely used as a basis for consideration, as if there were lights, you actually use candles.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.