- android - RelativeLayout 背景可绘制重叠内容
- android - 如何链接 cpufeatures lib 以获取 native android 库?
- java - OnItemClickListener 不起作用,但 OnLongItemClickListener 在自定义 ListView 中起作用
- java - Android 文件转字符串
根据关于 Bookmarklets 的维基百科文章 ( http://en.wikipedia.org/wiki/Bookmarklet ),Bookmarklets 的概念是:
Web browsers use URIs for the href attribute of the tag and for bookmarks. The URI scheme, such as http:, file:, or ftp:, specifies the protocol and the format for the rest of the string. Browsers also implement a prefix javascript: that to a parser is just like any other URI. Internally, the browser sees that the specified protocol is javascript, treats the rest of the string as a JavaScript application which is then executed, and uses the resulting string as the new page.
它表示生成的字符串用作新页面。那么这是否意味着浏览器拥有的原始 DOM 不受该字符串的影响?但是,如果仅将结果字符串用作新页面,我如何才能在现有 DOM 中更改或注入(inject)新的 DOM 元素?因为用于提醒 Hello 或注入(inject)一些新 DOM 元素的脚本实际上并没有返回任何内容。他们有点在现有的 DOM 上工作。
现在,在 Internet Explorer 中,除了使用 Bookmarklets 在页面上执行一些 JavaScript 之外,我还可以编写一个 BHO 插件并通过以下方式注入(inject)它:
document = (HTMLDocument)webBrowser.Document;
var injectedJS = System.IO.File.ReadAllText("InjectedJS.js");
var window = document.parentWindow;
window.execScript("(function(){ " + injectedJS + " })()");
类似在chrome中,我可以写一个扩展来实现同样的事情:
var s = document.createElement('script');
s.src = chrome.extension.getURL("script.js");
s.onload = function() {
this.parentNode.removeChild(this);
};
(document.head||document.documentElement).appendChild(s);
它们有什么不同?我的高级问题是:
execScript
方法或使用 javascript: 协议(protocol)执行 JavaScript 的方式有什么不同吗?最佳答案
1. Do these three approaches execute the javascript code in different environments?
所有这三种方法都在页面上下文中执行 JavaScript 代码。当这些方法相互比较时,您可以说 JavaScript 代码是在相同的环境中执行的。
内容脚本(Chrome/Opera/Firefox/Safari)运行在与网页隔离的环境中,所以从那个 Angular 来看,环境确实不同。
BHO 有点不同,因为与其他扩展平台不同,扩展的语言不是 JavaScript,而是 C++,C#,...... JavaScript 代码不能直接访问 BHO 的 native 代码(除非你自己实现这样的东西),所以环境肯定是“不一样”的。
2. Is there any limitation to one of them that another one doesn't have?
小书签是 javascript:...
网址,仅此而已。浏览器扩展可以直接执行跨源 HTTP 请求,访问持久的站点独立存储等。如果你想在书签中获得类似的功能,你需要使用外部 Web 服务。
Bookmarklet 只有在被用户手动激活时才能激活。这是优势还是劣势取决于您的情况。
小书签的最大大小受 maximum URL length 限制。 ,这是相当小的。可以通过插入 <script src>
来规避此限制。文档中的标签。必须首先加载脚本,因此代码的执行会延迟。
Bookmarklets 几乎可以在所有网络浏览器中使用,包括手机和平板电脑上的浏览器(Chrome 扩展只能用于桌面 Chromium 浏览器)。
3. Is there any difference in the way the result of the execution is presented to the user or is reflected back in browser?
没有。在所有情况下,您都在当前页面的上下文中运行代码。理论上,页面可以替换所有内置方法(例如 Function.prototype.call
、String.prototype.replace
、..),并干扰或滥用脚本的功能。
可能值得注意:Crossrider 和 Kango 扩展框架以类似于这三种方法的方式实现 Internet Explorer 的“内容脚本”功能。这意味着可以以检测使用这些框架编写的 IE 插件、拦截 API 声明并滥用其功能的方式制作页面。
4. Is there any difference at all between the terms "Javascript Injection" and "Bookmarklets"? Though I believe Javascript Injection is an effect and Bookmarklets are a way to achieve that, BHO and Chrome extensions being another.
小书签和“注入(inject)脚本”在概念上没有区别。本答案的第 2 部分解释了一些实际差异。
(通过“注入(inject)的脚本”,我假设您指的是 this method 我创造了这个术语来区分 Chrome 扩展中的脚本类型。Opera 12- 和 Safari 都使用这个术语来表示“内容脚本”).
5. If assumption in 4 is correct, is there any difference in the way javascript is executed using BHO's execScript method or using javascript: protocol in a browser?
除了前面提到的差异之外,没有。
关于javascript - JavaScript注入(inject)和书签有什么区别吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19950136/
我正在尝试创建一个在线书签系统。我已经设法从用户那里获取 URL 并将其存储到数据库中。但我也想采用“标题和标签”谁能帮我编写代码.. function add_bm($new_url) {
我目前正在开发一个动态使用数据库的应用程序。 这意味着它被设计为可以在任何时间、任何结构上与任何数据库一起使用。 我担心的是,我希望对某些记录进行“标记”或添加书签,因此我需要使用 Filter 属性
我正在创建一些许多人称之为书签栏的东西,但在网站本身内。基本上我有一个常规的 Bootstrap navbar很少有菜单项上有“图钉”。通过按图钉,用户可以固定该菜单项以快速访问我创建的侧边栏。 现在
我最近在聊天部分了解到,如果使用书签,则可以渲染 LaTeX: http://meta.math.stackexchange.com/a/3297 stackexchange 站点都渲染代码像这样。
我有这个可爱的 javascript 书签... javascript:var nam="blablabla&name"; var els=document.getElementsByName
我经常使用网页的三种变体,1) 开发网址,2) 预览/暂存网址,以及 3) 实时网址。 我想创建一个链接(小书签?)然后我可以添加到我的书签栏,这将更改部分 URL 字符串(基本上是页面名称),然后将
这个问题在这里已经有了答案: Add to browser favorites/bookmarks from JavaScript but for all browsers (mine doesn'
我正在尝试编写一个小书签来检测用户是否在已解析的页面上,如果他不在,则应将值传递给 API。 if (window.location.indexOf("thequeue.org") >= 0) {
有没有人知道为什么下面的 JavaScript 代码在 Firefox 上没有任何问题,并且在 IE7 上也能正常工作,但在 IE8 上却不行了?我不知道,我很感激任何提示:-) 我已将该代码作为收藏
一个页面中有很多链接,我需要快速单击其中包含文本“删除”的链接。这会导致 AJAX 请求,因此需要稍微暂停一下。什么是 JavaScript 书签代码(没有库,例如 jQuery),它将快速调用直接作
我需要一个可以单击按钮的 JavaScript 书签。问题是,页面上有 100 多个按钮,它们的值都相同。名字很独特,但是很长。 元素的全名类似于: actions[http://apps.faceb
我在制作 javascript 书签时遇到了问题,其中的代码同时包含 "" 引号和 '' 引号。举例来说,我的代码如下, Temporary HTML Doc
希望大家帮帮我。我似乎无法弄清楚如何制作一个小书签来选择网页下拉菜单中的选项。 希望实现:在我的chrome浏览器上做一个书签。当我在此页面上单击它时,它将选择下拉列表并在成员框中选择级别 2 网页的
当我浏览文件系统时,我设法在一个窗口中完成了繁琐的工作。 改善人体工程学,我决定为我最常用的目录创建书签,其短名称如:'lwt'、'eve' 等。但每次打开书签时,都会创建新的目录缓冲区,即使旧缓冲区
我正在努力了解 HATEOAS。 让我们通过一个例子来工作。客户端将浏览器加载到 getemails.com。为简单起见,让我们假设对 getemails.com 的调用访问了服务器并返回一个电子邮件
我想每周在 Safari 中备份一次。告诉我如何使用终端命令导出书签?谢谢你。 最佳答案 plutil -convert xml1 -o ~/Desktop/SafariBookmarks.xml ~
我想知道我们如何从 Mac OS X 上的另一个 Cocoa 应用程序访问 Safari 书签,以一种对 future 安全的方式。 您可能知道,检索 Safari 书签的常见机制有两种: 要么阅读
有谁知道如何通过 SDK 以编程方式访问“ map ”应用程序的书签?如果可能的话,我想阅读和书写书签。有想法吗? 谢谢! 最佳答案 我很确定答案是否定的。我考虑了两种可能的解决方案: 您可以直接访问
谁能告诉我怎么转 Top 又名页面顶部链接到书签。 不太了解 JavaScript,无法实现我想要的效果。 或者,如果我使用了错误的代码,那么你能不能帮我修好它,然后把它变成小书签。 最佳答案 创建
如何在vim中设置书签?我想为一些行和函数添加书签。你如何在代码上做书签?我的代码是用 C 编写的。 最佳答案 如果您输入 ma ,它将在当前位置的当前行上创建书签,名称为 a . 例如,键入 ma在
我是一名优秀的程序员,十分优秀!