通过JS访问Chrome的最后一个被检查的元素是$ 0和$ 1 [英] Accessing Chrome's last inspected element being $0 and $1 via JS

查看:301
本文介绍了通过JS访问Chrome的最后一个被检查的元素是$ 0和$ 1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Chrome浏览器的最后一个受检查的元素是否可以通过JavaScript访问?



背景知识,试图将其整合到一个名为onclick的Debug.js文件中。
https://stackoverflow.com/a/12596540/511438



我试图将上面提供的函数集成到可点击的元素上执行。



这是我的尝试,即使我已经检查
$ b

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

 函数CompareElements(a,b)
{
...按照上面的答案。
}

我怀疑$ 0是无法访问javascript的。有没有一种方法可以在javascript中执行此操作,而无需将整个功能粘贴到Chrome控制台中? 仅解决方案

Chrome扩展程序可以访问这些变量。有一个示例扩展使用 $ 0 ,它被称为Chrome查询,可在示例页面。我把它的代码修改了一下,最后用这个扩展。该代码可在 github 上获得。我不确定目前的格式是否有用,但有很大的改进空间。表格而不是树应该更具可读性,我会尽量在下周发生。




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?

解决方案

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.

这篇关于通过JS访问Chrome的最后一个被检查的元素是$ 0和$ 1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆