【问题标题】:Running custom functions with arguments from Chrome console从 Chrome 控制台运行带有参数的自定义函数
【发布时间】:2018-03-24 12:55:43
【问题描述】:

我想使用 Chrome 控制台运行一些 JavaScript 行。感谢tampermonkey,我得到了这个工作,我有这样的东西可以在任何网络上运行:

window.req= function(){

    token = getToken()...
    link = "http://hello.com/"  + parameter + "/token=" + token;
    window.open(link);
    };

这是完美的工作,我可以从页面中获取我需要的信息并在控制台上运行req()

我面临的问题是我完全无法发送参数。我通过像这样设置它们来做到这一点:

parameter = "thing"
req()

但是太丑了,我想做这样的:

req("thing")

但我无法让带有参数的自定义函数在 Chrome 的控制台上运行。

【问题讨论】:

    标签: javascript function google-chrome console tampermonkey


    【解决方案1】:

    这对我有用:

    window.getToken = function() { return "token12626"; }
    
    window.req= function(parameter){
        token = getToken()
        link = "http://hello.com/"  + parameter + "/token=" + token;
        window.open(link);
        };
    
    req("thing")
    

    【讨论】:

      猜你喜欢
      • 2014-04-30
      • 1970-01-01
      • 2012-03-10
      • 1970-01-01
      • 1970-01-01
      • 2019-09-22
      • 2014-12-17
      • 1970-01-01
      • 2012-08-22
      相关资源
      最近更新 更多