标签云

微信群

扫码加入我们

WeChat QR Code

如何将jQuery网页[复制]

This question already has an answer here:

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);


Just to make this a little more portable, you should remove the http: portion and make the link just //ajax.googleapis.com.... That way, the bookmarklet will work on http and https pages.

2018年05月28日14分28秒

Better to enforce https, since https is ok on every other protocol, especially on file:// documents where // fails.

2018年05月28日14分28秒