简体   繁体   English

在Javascript控制台中控制Chrome Web Inspector?

[英]Control Chrome Web Inspector in Javascript console?

Is there anyway to control the Chrome Web Inspector in the JavaScript console? 无论如何,是否可以在JavaScript控制台中控制Chrome Web Inspector?

For example, say I wanted to select an element (#test_element) in the "Elements" panel. 例如,假设我想在“元素”面板中选择一个元素(#test_element)。 Normally I right click on the element and choose "Inspect Element". 通常,我右键单击该元素,然后选择“检查元素”。

I'd like to do this in the JavaScript console, using something like: 我想在JavaScript控制台中执行以下操作:

webInspector.inspectElement("#test_element");

I'd like to be able to access the entire UI of the web inspector this way. 我希望能够以这种方式访问​​Web检查器的整个UI。 I'm open to using extensions for this as well. 我也愿意为此使用扩展。

Use inspect for this purpose. 为此使用inspect Since you want to use a selector, combine it with the console's $ alias for document.querySelector . 由于要使用选择器,因此请将其与控制台的$ 别名结合用于document.querySelector If the page overrides $ , because it uses jQuery, use $$(selector)[0] to get a reference to the DOM element (anything would do, as long as it's a reference to a DOM node). 如果页面重写$ ,因为它使用jQuery,则使用$$(selector)[0]获取对DOM元素的引用(只要它是对DOM节点的引用,任何操作都可以)。

From the Command Line Api Reference 从命令行Api参考

inspect(object)

Opens and selects the specified element or object in the appropriate panel: either the Elements panel for DOM elements and the Profiles panel for JavaScript heap objects. 在适当的面板中打开并选择指定的元素或对象:DOM元素的Elements面板和JavaScript堆对象的Profiles面板。

The following example opens the first child element of document.body in the Elements panel: 以下示例在“元素”面板中打开document.body的第一个子元素:

 inspect(document.body.firstChild); 

暂无
暂无

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

相关问题 Chrome Web检查器:CPU分析器 - Chrome web inspector : CPU profiler 在控制台中调用原型方法时,Chrome Web检查器显示异常符号 - Chrome Web inspector shows unusual symbol when calling prototype method in console 在Chrome检查器中查找OnKeyPress JavaScript - Find OnKeyPress JavaScript in Chrome Inspector Chrome Inspector中的Javascript调试:变量未在手表和控制台中显示,但在悬停时可以检查 - Javascript debugging in Chrome Inspector: variables are shown undefined in watches and console but can be inspected when hovered 对url进行htaccess修改会在Chrome Inspector控制台中导致引导源地图上的无休止javascript循环错误 - htaccess modification for pretty urls causes endless javascript loop on bootstrap sourcemap error in Chrome Inspector console 禁用节点检查器Chrome控制台错误 - Disable node-inspector Chrome console errors 是否可以从外部javascript访问控制台命令行API(例如Firebug或Chrome Inspector控制台的$$和traceAll)? - Can I access the console Command line API (like $$ and traceAll from Firebug or Chrome Inspector Console) from an external javascript? 如何在Google Chrome浏览器中查看Web请求 - How to see web requests in Google chrome inspector 使用Chrome Web Inspector在行中间添加断点 - Adding a breakpoint in the middle of a line with Chrome Web Inspector Javascript浏览器检查器控制台与源代码 - Javascript browser inspector console vs source code
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM