Using jQuery on sites like Gmail or Facebook

I try to automatically enter users into websites, given their username and password. To do this, I use the Chrome extension, where each page will load my script content, which will try to find out where the username and password fields are, and then send.

The content of the script loads jQuery and for the search I am doing something along these lines:

$("input[type=password]") OR $(".password") OR $("#password")

This usually works, but on sites such as Facebook or Gmail, it fails (although it shouldn't). I suspect this is because they are already using some internal jQuery version that does not do the same.

How to fix it? Perhaps changing the jQuery dollar sign that I upload to another corrects this, because then it will not conflict with the internal version of jQuery. Is it possible?

+3
source share
4 answers

jQuery.noConflict ()

var $j = jQuery.noConflict();
// Use jQuery via $j(...)
$j(document).ready(function(){
   $j("div").hide();
});
+3
source

Check http://code.google.com/chrome/extensions/content_scripts.html#execution-environment .

Isolated worlds allow each script content to make changes to its JavaScript environment without worrying about a conflict with the page or with other content scripts. For example, the contents of the script might include jQuery v1, and the page might include jQuery v2, and they would not conflict with each other.

JQuery gmail yahoo script . gmail - "Passwd". , $("#Passwd") . , $("input[type=password]") . .

+1

A quick look at the main page of the Facebook (minified) script seems to suggest that they use jQuery internally. At least there is a function in the script that has the name '$', so using a different name for your particular jQuery object would be a good idea. It will also prevent this problem in the future.

A Jasie post shows how to change a jQuery variable.

0
source

In jQuery 1.5, you can use the new sub () function .

$$ = jQuery.sub();
$$("input[type=password]") ..... your code here ...
0
source

Source: https://habr.com/ru/post/1790286/


All Articles