-1

As the title says, Can I disable JQuery in browsers?

I wrote a JQuery function for my website and thought that if any user disable the JQuery like we disable the JS, then what should I do for that.

We disable the JavaScript from settings in our browser, like that, is it possible to disable the JQuery?

I searched for a while on this questions:

Disable Jquery in certain sections

Is possible to disable Javascript/Jquery from the browser inspector console?

But in the first question, the user is asking for a particular section and in the second question, the user is asking for a console. So I couldn't find a proper answer for my question. Can anyone know is it possible. If yes, how?

Thank You.

Vaibhav Mandlik
  • 51
  • 2
  • 13

5 Answers5

1

If you wished to disable jQuery specifically, one option would be to make window.jQuery and window.$ unwritable before the document loads, possibly with a userscript. For example, the following userscript disables jQuery on this question's page, which results in many script errors in SO's Javascript, but does not disable other Javascript that does not rely on jQuery:

// ==UserScript==
// @name         Break-jQuery
// @namespace    CertainPerformance
// @version      1
// @match        https://stackoverflow.com/questions/51807987/can-i-disable-jquery-in-browsers
// @run-at       document-start
// @grant        none
// ==/UserScript==

Object.defineProperty(window, 'jQuery', {
  value: undefined,
  writable: false
});
Object.defineProperty(window, '$', {
  value: undefined,
  writable: false
});

But there's not much of a reason to do this - better to either disable Javascript entirely, or allow a site to use jQuery, if it wants to.

CertainPerformance
  • 356,069
  • 52
  • 309
  • 320
1

But in a quirky manner you have to accomplish this.

jQuery(document).ready(function() {
   jQuery = null;
   $ = null;  // or undefined or 
   // delete jQuery; delete $;
});

If other methods already initialized then this won't help. But further method implementation wont work.

Incase other methods or functions or bindings if happening should have to start after this.

$(document).on('click', function() {
  console.log("previous bind successfully working");
});

$(document).ready(function() {
  console.log('jquery enabled');
  delete jQuery;
  delete $;
  try {
    console.log($(document));
    console.log('jQuery', jQuery, $);
  } catch (e) {
    console.log(e, 'in catch block');
  }
  setTimeout(function() {
    try {
      $(document).on('click', function() {
        console.log("bind successfull with jquery");
      });
    } catch (e) {
      console.log(e, 'in catch block');
    }
  }, 100);
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>

If in browser you want to do this, as i said, if once jquery is initialized with functionalities its very hard to unbind them. If there is later reference of jquery it wont work with above code if ran in console.

Priya
  • 1,522
  • 1
  • 14
  • 31
0

You can disable jQuery in your browser by disabling JavaScript. jQuery is just a library written in JavaScript, not its own language.

You can't disable just jQuery while allowing other JavaScript in browser settings. It would be possible to write a browser extension/add-on that did that, but it wouldn't be very useful.

In a comment you've said:

Actually I wrote a jquery function for my website and thought if some user disable the jquery like JS then what should I do for tha.

The user won't specifically disable jQuery, but they may well disable JavaScript. (It's quite rare these days, but people do still do it.) If you want to tell the user that your site works better when JavaScript is enabled, include noscript content:

<noscript>
Your message goes here
</noscript>

That content will only be shown to users with JavaScript disabled (or in a browser that doesn't support JavaScript at all).

T.J. Crowder
  • 1,031,962
  • 187
  • 1,923
  • 1,875
0

JQuery is javascript. Since it is not a special type of language and the JQuery file can be attached in any name in an HTML document, it cannot be disabled.

However disabling Javascript will disable JQuery.

Steev James
  • 2,396
  • 4
  • 18
  • 30
0

Your Concern is,

We disable the JavaScript from settings in our browser, like that, is it possible to disable the JQuery?

The straight answer is NO

First,
You have to understand that Javascript is an embedded scripting language for the web.

Second,
jQuery is just a library and which is not embedded into the browser(It is not a browser feature how can you disable that in the browser?)



Furthermore disabling jQuery(by means of some extensions, I don't know) Would make almost all websites Useless

Anandhu
  • 807
  • 1
  • 9
  • 22