小编Bro*_*ams的帖子

尝试解析AJAX响应时出现“ getElementById不是函数”?

我正在运行GM_xmlhttpRequest(使用Greasemonkey脚本),并将其存储responseText到新创建的HTML元素中:

var responseHTML = document.createElement('HTML');
...
onload: function() { responseHTML.innerHTML = response.responseText; }
Run Code Online (Sandbox Code Playgroud)


然后我试图在中找到一个元素responseHTML

console.log(responseHTML.getElementsByTagName('div'));
console.log(responseHTML.getElementById('result_0'));
Run Code Online (Sandbox Code Playgroud)


第一个工作正常,但第二个则不行。有任何想法吗?

javascript greasemonkey xmlhttprequest getelementbyid gm-xmlhttprequest

1
推荐指数
1
解决办法
6189
查看次数

谷歌Chrome,同源政策杀死了Tampermonkey脚本

我有一个自己完成的脚本,当我访问它时,它使用jQuery Ajax函数来记录网页中的一些数据.它需要一些信息并将其发送到我的本地Apache主机以保存在文本文件中.

它工作了几个月,但我现在得到一个与此同源策略相关的错误(我知道它是如何工作的及其目的),浏览器现在正在结束显示此消息的脚本执行:

The page at https://www.website.com/ displayed insecure content from
http://127.0.0.1:8081/whatever.php
Run Code Online (Sandbox Code Playgroud)

其次是:

Refused to connect to connect 'http://127.0.0.1:8081/whatever.php?arguments=1' because it 
violates the following Content Security Policy directive: "connect-src
https://www.website.com/* https://*.website.com/
https://*.website.net xhr: error: SECURITY_ERR: DOM Exception 18 
Run Code Online (Sandbox Code Playgroud)

最后一个域在错误消息上显示为红色.一个奇怪的细节是,在Tampermonkey上的JavaScript代码中,我有@includes那些域而不是红色标记的域.我添加了它并进行了测试,但没有奏效.

我在谷歌上发现的每一个讨论都说明了如何禁用这个政策,但是如果你正在开发一个扩展,那不是我的情况.

这段代码只能在我的机器上运行,我没有打算以任何方式分发它,所以任何解决方案都会受到赞赏,即使解决方案是直接更改浏览器配置.

如果这个'有用,我使用的是Windows 7.

javascript jquery greasemonkey google-chrome tampermonkey

1
推荐指数
1
解决办法
2181
查看次数

在内容脚本中使用jquery进行Chrome扩展可在创建对话框窗口时解决错误

我尝试在Chrome扩展程序中使用jQuery和jQuery-UI.每次创建新选项卡时,我都会尝试在内容脚本对话框窗口中创建但我会继续:

Property '$' of object [object Window] is not a function 
Run Code Online (Sandbox Code Playgroud)

我想我在加载脚本时做错了.这就是我所拥有的:

{
"name":"Sample",
"description":"This is a sample",
"manifest_version":2,
"version":"2",
"background":{
    "scripts":["background.js"]
},
"content_scripts": [
    {
      "matches": ["<all_urls>"],
      "js": ["jquery-1.8.3.min.js","jquery-ui.js","client.js","myscript.js"]
      "run_at":"document_end",
      "all_frames": true
    }
  ],
"web_accessible_resources": [
    "client.js","jquery-1.8.3.min.js","jquery-ui.js"
  ],
"permissions": [ 
        "unlimitedStorage",
        "http://*/",
        "<all_urls>",
        "tabs"
   ]
}
Run Code Online (Sandbox Code Playgroud)


myscript.js(内容脚本):

var ss = document.createElement('script');
ss.type = "text/javascript";
ss.src = chrome.extension.getURL('jquery-1.8.3.min.js');
ss.onload = function() {
    ss.parentNode.removeChild(ss);
     console.log("jquery-1.8.3.min.js loaded");

};

var ss_ui = document.createElement('script');
ss_ui.type = "text/javascript";
ss_ui.src = chrome.extension.getURL('jquery-ui.js');
ss_ui.onload = function() { …
Run Code Online (Sandbox Code Playgroud)

jquery jquery-ui google-chrome-extension

1
推荐指数
1
解决办法
2364
查看次数

即使指定了@grant,Greasemonkey AJAX帖子似乎也不起作用

我的脚本不起作用.AJAX调用没有发生.为什么?

// ==UserScript==
// @name        prova
// @namespace   http://blogpagliaccio.wordpress.com/
// @description prova
// @include     http://*
// @version     1
// @grant       GM_xmlhttpRequest
// @require     http://userscripts.org/scripts/source/85398.user.js
// ==/UserScript==

// [........... other code]

    console.log('start ajax call...');
            GM_xmlhttpRequest({
                    method: "POST",
                    url: "www.prova.it",
                    data: {parametro:parametro},
                    onload: function(response) {
                            console.log(response.responseText);
                    },
                    onerror: function(reponse) {
                            alert('error');
                            console.log(reponse);
                    }
            });
Run Code Online (Sandbox Code Playgroud)


我在一个@grant指令中列出了API函数,但是我没有看到AJAX调用和响应.

javascript greasemonkey http-post gm-xmlhttprequest

1
推荐指数
1
解决办法
6143
查看次数

通过window.location更改URL后如何运行代码?

我正在这样做,但它不起作用:

window.addEventListener("load", function load(event){
    alert('hola');
},false);

window.location.assign("about:blank");
Run Code Online (Sandbox Code Playgroud)

这是一个 Greasemonkey 脚本。新位置已加载,但警报从未显示。

javascript greasemonkey onload window.location

1
推荐指数
1
解决办法
9802
查看次数

模糊代码在Greasemonkey脚本中引发错误

我有一个Greasemonkey脚本,我想要混淆.我想知道可用的"Packer"Javascript混淆器出了什么问题.

它压缩脚本很好,但安装后,脚本不起作用.是否有任何PHP类会混淆/打包GM脚本并保留功能?或者我该怎么做呢?

错误:

Timestamp: 01-05-2013 13:11:35
Error: missing ; before statement
Source File: file://file_path
Line: 1
Run Code Online (Sandbox Code Playgroud)

脚本:

// ==UserScript==
// @name           Test
// @namespace      http://*
// @description    Test
// @require         http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js
// ==/UserScript==

var SomeVar = "Something";
GM_setValue("foo","bar");
var AnotherVar = GM_getValue("foo");
alert(AnotherVar);
Run Code Online (Sandbox Code Playgroud)

打包脚本:

eval(function(p,a,c,k,e,r){e=String;if(!''.replace(/^/,String)){while(c--)r[c]=k[c]||c;k=[function(e){return r[e]}];e=function(){return'\\w+'};c=1};while(c--)if(k[c])p=p.replace(new RegExp('\\b'+e(c)+'\\b','g'),k[c]);return p}('0 3="4";5("1","6");0 2=7("1");8(2);',9,9,'var|foo|AnotherVar|SomeVar|Something|GM_setValue|bar|GM_getValue|alert'.split('|'),0,{}))
Run Code Online (Sandbox Code Playgroud)

javascript php obfuscation greasemonkey

1
推荐指数
1
解决办法
3318
查看次数

如何在javascript中为所有浏览器添加到收藏夹/书签

我在使用java脚本添加到收藏夹/书签网页时有一些查询.我只是通过此链接获取此源代码.它在上个月一直运作良好.但现在它不适用于任何浏览器.这是我的代码:

function CreateBookmarkLink(){
        var title = document.title;
        var url = document.location.href;

        if(window.sidebar){
            /* Mozilla Firefox Bookmark */
            window.sidebar.addPanel(title, url, "");
        }else if(window.external){
            /* IE Favorite */
            window.external.AddFavorite(url, title);
        }else if(window.opera && window.print) {
            /* Opera Hotlist */
            alert("Press Control + D to bookmark");
            return true;
        }else{
            /* Other */
            alert("Press Control + D to bookmark");
        }
 <a href="javascript:CreateBookmarkLink();">Add to Favorites/Bookmark</a>
Run Code Online (Sandbox Code Playgroud)

它不再适用于任何浏览器,只显示:

TypeError:window.sidebar.addPanel不是函数
> window.sidebar.addPanel(title,url,"");

任何想法如何解决?我还需要在Chrome浏览器中添加收藏夹.任何其他想法为我的网站创建书签.

javascript jquery bookmarks

1
推荐指数
1
解决办法
3万
查看次数

通过按键触发警报

我正在写一个 Greasemonkey 脚本。我想在用户按下“Q”键时触发某个代码运行。我做了一些研究,我看到的大多数来源都建议使用window.onkeypress.

为了测试此方法,我创建了一个用户脚本,设置为在用户按下 时运行Q。这是我的代码:

window.onkeypress = function(event) {
   if (event.keyCode == 81) {
   alert("This is a test.")
   }
}
Run Code Online (Sandbox Code Playgroud)


然而,按下 Q 键后,什么也没发生。我想知道是否有人知道这可能是为什么以及我可以做些什么来纠正它。

此外,如果有人知道我可以用来达到相同效果的任何其他方法,将不胜感激。

javascript greasemonkey keypress userscripts tampermonkey

1
推荐指数
1
解决办法
5849
查看次数

索赔和SAML2混淆

我的理解是声明是基于WS-trust标准的STS事物,与SAML2标准无关.WS-trust STS令牌可以使用SAML以该格式发送声明.我对么?

claims-based-identity claims sts-securitytokenservice saml-2.0 ws-trust

1
推荐指数
1
解决办法
4148
查看次数

如何检索我正在使用的页面(JQuery的数据角色属性)?

我有:

<div id="page-1" data-role="page">
</div>

<div id="page-2" data-role="page">
</div>
Run Code Online (Sandbox Code Playgroud)

在我的javascript代码中的一些函数我会写:

 $.mobile.navigate('page-2');
Run Code Online (Sandbox Code Playgroud)

在另一个函数中,我将要检索我当前使用的页面:

(在本例中为第2页)

有没有办法在不使用全局变量的情况下执行此操作?(通过使用某种方法?)

javascript jquery jquery-mobile

1
推荐指数
1
解决办法
884
查看次数