简体   繁体   English

是否可以从外部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?

Is it possible to access the Command Line Api from an external api? 是否可以从外部api访问命令行Api

Simple Example: 简单的例子:

HTML HTML

  <div id="myDiv"></div>
  <script src="myScript.js"></script>

myScript.js myScript.js

$$('#myDiv').textContent = 'this will not work';

I do not wan't to load an external library like jQuery or Zepto because seens like this is already loaded locally. 我不想加载像jQuery或Zepto这样的外部库,因为这样的视图已经在本地加载了。

To answer your question, no. 要回答您的问题,不。 But I don't think you really want to. 但是我不认为你真的想要。 The API may change, breaking your code. API可能会更改,从而破坏您的代码。 If all you're looking for is the query selector. 如果您只需要查询选择器。 I think you are better off using a snippet found on the MDN. 我认为您最好使用MDN上的代码段。

function $ (selector, el) {
    if (!el) {el = document;}
    return el.querySelector(selector);
}
function $$ (selector, el) {
    if (!el) {el = document;}
    return el.querySelectorAll(selector);
    // Note: the returned object is a NodeList.
    // If you'd like to convert it to a Array for convenience, use this instead:
    // return Array.prototype.slice.call(el.querySelectorAll(selector));
}
alert($('#myID').id);

Document.querySelector Document.querySelector

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

相关问题 如何过滤来自 Firebug 控制台的 AJAX 请求? - How can I filter AJAX requests from console in Firebug? 如何从Firebug的控制台访问Firebug的信息? - How to access Firebug's information from Firebug's console? 如何在包装Firebug(或类似的)控制台api时访问行号 - How to access line numbers when wrapping Firebug (or similar) Console api 从命令行打开Chrome / Chromium,然后将javascript操作发送到chrome / chromium控制台 - Open Chrome/Chromium from command line and send javascript action to chrome/chromium console 是否可以在Chrome中从控制台加载外部javascript文件(从URL)? - Is it possible to load external javascript files (from URLs) from the console, in chrome? 与Firebug / Chrome控制台中的require.js模块交互? - Interacting with require.js modules from the Firebug/Chrome console? 在Javascript控制台中控制Chrome Web Inspector? - Control Chrome Web Inspector in Javascript console? Vuejs,从 chrome 检查器控制台设置绑定到 model 的输入值 - Vuejs , set input value bound to a model from chrome inspector console 您能以编程方式访问Firebug控制台输出吗? - Can you programmatically access the Firebug console output? 如何从终端执行Firebug控制台JavaScript命令? - How to execute Firebug console JavaScript commands from terminal?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM