如何将jquery注入任何网页 [英] How to inject jquery to any webpage

查看:1089
本文介绍了如何将jquery注入任何网页的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有没有办法将jQuery注入任何页面,就像我们使用javascript(来自url)一样。
使用javascript我们这样做

Is there any way to inject jQuery into any page as we do with javascript(from url). with javascript we do this

javascript:alert("b");

我试过这个,但我不知道为什么它不起作用

I tried this but I don't know why it dosen't work

javascript:var x = document.getElementsByTagName("head")[0];
var y = document.createElement("script");
y.src = "http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js";
x.appendChild(y);

var a = document.getElementsByTagName("body")[0];
var b = document.createElement("script");
b.innerHTML = "$('p').css('border','3px solid red')"
a.appendChild(b);


推荐答案

这是一个用于在任何网页中注入jquery的bookmarklet代码:

This is a bookmarklet code to inject jquery in any webpage:

javascript:(function() {
    function l(u, i) {
        var d = document;
        if (!d.getElementById(i)) {
            var s = d.createElement('script');
            s.src = u;
            s.id = i;
            d.body.appendChild(s);
        }
    }
    l('//code.jquery.com/jquery-3.2.1.min.js', 'jquery')
})();

更新:
我从中移除了http:部分@Monkpit评论的网址,非常重要,可以节省很多问题。

Update: I removed the http: part from the URL per @Monkpit comment, which is very important and saves a lot of problems.

这篇关于如何将jquery注入任何网页的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆