Accessing Chrome's last inspected element being $0 and $1 via JS

给你一囗甜甜゛ 提交于 2019-12-11 06:29:04

问题


Can Chrome's last inspected elements be access with javascript?

Background, trying to integrate this into a Debug.js file to be called onclick. https://stackoverflow.com/a/12596540/511438

I am trying to integrate the function provided above to execute on a clickable element.

Here is my attempt which results in undefined even though i have inspected elements prior to executing this.

$(document).on('click', "#debugelements", 
    function () { CompareElements(window.$0, window.$1); });

and

function CompareElements(a, b)
{
... as per the answer above.
}

i suspect $0 is inaccessable to javascript. Is there a way to do this in javascript without pasting the whole function into the Chrome console?


回答1:


I'm afraid that only Chrome Extensions have access to these variables. There is a sample extension that makes use of $0, it's called 'Chrome Query' and is available on samples page. I took it's code, modified a little and ended up with this extension. The code is available on github. I'm not sure if it's extra useful in current form, but there is a lot of space for improvement. Table instead of a tree should be more readable, I'll try to make it happen next week.



来源:https://stackoverflow.com/questions/12611440/accessing-chromes-last-inspected-element-being-0-and-1-via-js

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!