简体   繁体   English

如何使用Chrome开发人员工具执行一段JavaScript代码

[英]How to execute a piece of JavaScript code using Chrome developer tools

I use Google Chrome and its developer tools like ' Inspect element ' to check performance of my web pages. 我使用Google Chrome浏览器及其“ 检查元素 ”之类的开发人员工具来检查网页的性能。 I know that its Developer tool ' Console ' can be used to execute JavaScript. 我知道其开发人员工具“ Console ”可用于执行JavaScript。

I was just saving my one interested web page on my Delicious web account and I noticed that all that information it needs goes through JavaScript , So I just tried to put that code on my JS Console so that I can see the whole background process, but it failed. 我只是将一个感兴趣的网页保存在Delicious网络帐户中,我注意到它所需的所有信息都通过JavaScript传递,所以我只是试图将该代码放在JS控制台中,以便可以看到整个后台过程,但是它失败了。 Can anyone please tell me how should I work with it, because I know this can be done. 谁能告诉我我应该如何使用它,因为我知道这是可以做到的。

The things I am seeing 我看到的东西 当我单击书签时

The code you will need to save as your bookmark 您将需要保存为书签的代码

javascript:(function(e,t)%7Bvar n=e.document;setTimeout(function()%7Bfunction a(e)%7Bif(e.data==="destroy_bookmarklet")%7Bvar r=n.getElementById(t);if(r)%7Bn.body.removeChild(r);r=null%7D%7D%7Dvar t="DELI_bookmarklet_iframe",r=n.getElementById(t);if(r)%7Breturn%7Dvar i="https://delicious.com/save?",s=n.createElement("iframe");s.id=t;s.src=i+"url="+encodeURIComponent(e.location.href)+"&title="+encodeURIComponent(n.title)+"&note="+encodeURIComponent(""+(e.getSelection?e.getSelection():n.getSelection?n.getSelection():n.selection.createRange().text))+"&v=1.1";s.style.position="fixed";s.style.top="0";s.style.left="0";s.style.height="100%25";s.style.width="100%25";s.style.zIndex="16777270";s.style.border="none";s.style.visibility="hidden";s.onload=function(){this.style.visibility="visible"};n.body.appendChild(s);var o=e.addEventListener?"addEventListener":"attachEvent";var u=o=="attachEvent"?"onmessage":"message";e[o](u,a,false)},1)})(window)

Details: I've an account on delicious.com which provides me a service to save my interested web links. 详细信息:我在Delicious.com上有一个帐户,该帐户为我提供了保存我感兴趣的Web链接的服务。 for example If I am visiting a Stackoverflow question page and I like the question I just need to click on the bookmark(I've provided you the URL above), I am wondering how it fetches its parent page and saves it in their database, How it can be done using just javascript, I always noticed bookmarks with only web addresses but this one contains javascript code, Can anyone please tell me how it works, Thanks 例如,如果我正在访问Stackoverflow问题页面,而我只需要单击书签(我已经为您提供了上面的URL),我想知道该问题如何获取其父页面并将其保存在他们的数据库中,仅使用javascript即可完成操作,我总是注意到只有网址的书签,但是其中包含javascript代码,谁能告诉我它是如何工作的,谢谢

What you tried to execute is a JavaScript pseudo-scheme . 您尝试执行的是JavaScript pseudo-scheme Note the javascript: part at the beginning. 请注意开头的javascript:部分。 Doesn't it sound familiar with other schemes like http: , https: , ftp: ? 听起来不熟悉其他方案,例如http:https:ftp:吗?

It would be executed in the URL, not in the Console. 它将在URL中执行,而不是在控制台中执行。 In other words, you use JavaScript pseudo-scheme to execute a piece of JavaScript code, in the address bar of the browser . 换句话说,您可以使用JavaScript pseudo-scheme 在浏览器的地址栏中执行一段JavaScript代码。

To execute it in Console, you have to do two things: 要在控制台中执行它,您必须做两件事:

  1. Remove javascript: scheme 删除javascript: scheme
  2. Because it's supposed to be executed in the URL, it's URL encoded. 因为它应该在URL中执行,所以它是URL编码的。 You have to decode it first. 您必须先对其进行解码。 See that %7B ? 看到那个%7B吗? It represents { . 它代表{ Console won't recognize it, till it's decoded to the original character. 在将其解码为原始字符之前,控制台将无法识别它。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何在Chrome开发者工具中排序最小化的javascript代码? - how to sort minimalized javascript code in chrome developer tools? 如何在 chrome 开发者工具中自动化需要点击 javascript 按钮的代码 - How to automate the code that requires the click of a button in javascript in chrome developer tools "使用 Chrome 开发者工具编辑 Javascript" - Editing Javascript using Chrome Developer Tools 如何在 Chrome 开发者工具中禁用 JavaScript? - How to disable JavaScript in Chrome Developer Tools? 如何以编程方式在chrome developer工具中禁用javascript? - How to disable javascript in chrome developer tools programmatically? Javascript 代码只能在 Chrome 开发者工具打开时在 Chrome 中工作 - Javascript code only works in Chrome while Chrome Developer Tools are open 从开发者工具调试 Chrome Javascript 引擎源代码 - Debugging Chrome Javascript engine source code from Developer Tools Chrome开发人员工具javascript版本 - Chrome developer tools javascript version 是否可以使用Chrome Developer工具重新加载单个Javascript文件? - Is it possible to reload a single Javascript file using Chrome Developer tools? 使用Chrome开发人员工具只能看到一个JavaScript文件 - Only able to see one JavaScript file using Chrome developer tools
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM