我试图找到一种创建书签的方法,该书签将从其他html和css加载(从外部文件)新的图层/ div并将其覆盖在现有页面上。
有没有人有一个书签示例,他们可以分享吗?
我可以使用新的html内容和CSS类创建div我不知道如何编写bookmarklet和javascript / jquery函数来在现有页面上加载新内容。
非常感谢!
答案 0 :(得分:2)
尝试使用此代码,显然它可以改进,但它可以工作。您必须对其进行微调,并确保在将其粘贴到浏览器地址栏之前添加“javascript:”。
javascript : (function (e, a, g, h, f, c, b, d) {
if (!(f = e.jQuery) || g > f.fn.jquery || h(f)) {
c = a.createElement("script");
c.type = "text/javascript";
c.src = "http://ajax.googleapis.com/ajax/libs/jquery/" + g + "/jquery.min.js";
c.onload = c.onreadystatechange = function () {
if (!b && (!(d = this.readyState) || d == "loaded" || d == "complete")) {
h((f = e.jQuery).noConflict(1), b = 1);
f(c).remove()
}
};
a.documentElement.childNodes[0].appendChild(c)
}
})(window, document, "1.3.2", function ($, L) {
//your code here (a div with some content)
$("<div style='width:500px;height:400px; border:5px solid black; background-color:white; box-shadow:10px 10px 10px black; position:fixed; top: 150px; left:150px; z-index:99999'><h1 style='margin:150px'>hello world</h1></div>").appendTo("body");
});
编辑:
这里使用嵌入在iframe中的外部文档的代码相同:
javascript:(function(e,a,g,h,f,c,b,d){if(!(f=e.jQuery)||g>f.fn.jquery||h(f)){c=a.createElement("script");c.type="text/javascript";c.src="http://ajax.googleapis.com/ajax/libs/jquery/"+g+"/jquery.min.js";c.onload=c.onreadystatechange=function(){if(!b&&(!(d=this.readyState)||d=="loaded"||d=="complete")){h((f=e.jQuery).noConflict(1),b=1);f(c).remove()}};a.documentElement.childNodes[0].appendChild(c)}})(window,document,"1.3.2",function($,L){$("<div style='width:500px;height:400px; border:5px solid black; background-color:white; box-shadow:10px 10px 10px black; position:fixed; top: 150px; left:150px; z-index:99999'><iframe style='width:100%; height:100%;' src='http://www.htmlcodetutorial.com/frames/hello.html'></iframe></div>").appendTo("body");});