Secret copy to clipboard JavaScript function in Chrome and Firefox?

后端 未结 2 1462
别那么骄傲
别那么骄傲 2020-12-04 10:02

Update

Looks like browsers are starting to support copy natively in JS


In the console windows of both Chrome and Firefox on Mac I can

相关标签:
2条回答
  • 2020-12-04 10:25

    Here you can see the reference copy command of Chrome Dev tools: https://developers.google.com/web/tools/chrome-devtools/console/utilities#copy

    You shouldn't use this commands on real JS cross-browsers (just for debugging on the console so-to-speak).

    0 讨论(0)
  • 2020-12-04 10:38

    I believe these are predefined Firebug console functions - at least that seems to be the case for Firebug. If you try calling window.copy for instance, you'll get a warning about function not defined, so it's definitely not a browser function, and cannot be used in normal JavaScript files. The following functions also seems to work in the JavaScript console, after playing around with it a bit:

    • clear()
    • profile()

    Running these in the Chrome console reveals the source behind these functions in the Webkit console:

    > profile
    function ()
    {
    return console.profile.apply(console, arguments)
    }
    
    > clear
    function ()
    {
    InjectedScriptHost.clearConsoleMessages();
    }
    
    > copy
    function (object)
    {
    if (injectedScript._type(object) === "node")
    object = object.outerHTML;
    InjectedScriptHost.copyText(object);
    }
    

    While the Firebug source also defines a list of functions:

    this.clear = function()  // no web page interaction
    {
        Firebug.Console.clear(context);
    };
    
    this.inspect = function(obj, panelName)  // no web page interaction
    {
        Firebug.chrome.select(obj, panelName);
    };
    
    this.keys = function(o)
    {
        return FBL.keys(o);  // the object is from the page, unwrapped
    };
    
    this.values = function(o)
    {
        return FBL.values(o); // the object is from the page, unwrapped
    };
    
    // etc...
    
    0 讨论(0)
提交回复
热议问题