小编Sau*_*ena的帖子

通过属性名称获取HTML元素

JavaScript中有一些方法可以使用ID,Class和Tag来获取HTML元素.

document.getElementByID(*id*);
document.getElementsByClassName(*class*);
document.getElementsByTagName(*tag*);
Run Code Online (Sandbox Code Playgroud)

是否有任何方法可以根据属性名称获取元素.

EX:

<span property="v:name">Basil Grilled Tomatoes and Onions</span>
Run Code Online (Sandbox Code Playgroud)

喜欢:

document.getElementsByAttributeName("property");
Run Code Online (Sandbox Code Playgroud)

html javascript dom

50
推荐指数
2
解决办法
8万
查看次数

java.lang.NoClassDefFoundError:org/apache/http/client/HttpClient

我正在尝试从GWT servlet发出get请求以从Web服务获取JSON响应.以下是我的servlet中的代码:

public String getQueData() throws IllegalArgumentException {
    String message = null;
    try {           
        HttpClient httpclient = new DefaultHttpClient(); 
        JSONParser parser = new JSONParser();

        String url = "working - url";
        HttpResponse response = null;
        response = httpclient.execute(new HttpGet(url));

        JSONObject json_data = null;
        json_data = (JSONObject)parser.parse(EntityUtils.toString(response.getEntity()));
        JSONArray results = (JSONArray)json_data.get("result");
        for (Object queid : results) {
            message = message.concat((String) ((JSONObject)queid).get("id"));
            message = message.concat("\t");
            message = message.concat((String) ((JSONObject)queid).get("owner"));
            message = message.concat("\n");
        }
      } catch (Exception e) {
    message = e.toString();
    }
    return …
Run Code Online (Sandbox Code Playgroud)

java gwt json servlets

48
推荐指数
2
解决办法
17万
查看次数

没有源代码可用于类型:GWT编译错误

我试图在我的GWT应用程序中通过servlet获取请求.在编译代码时,我收到了这些错误.

[ERROR] Line 16: No source code is available for type org.apache.http.client.ClientProtocolException; did you forget to inherit a required module?
[ERROR] Line 16: No source code is available for type org.apache.http.ParseException; did you forget to inherit a required module?
[ERROR] Line 16: No source code is available for type org.json.simple.parser.ParseException; did you forget to inherit a required module?
Run Code Online (Sandbox Code Playgroud)

我该怎么做才能消除这些错误?GWT不支持这些类吗?

以下是我正在使用的代码

public String getJSON() throws ClientProtocolException, IOException, ParseException{
    HttpClient httpclient = new DefaultHttpClient(); 
    JSONParser parser = new JSONParser();
    String url = …
Run Code Online (Sandbox Code Playgroud)

java gwt json http-get httpresponse

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

使用jQuery进行跨域请求

对于一个项目,我需要获取不同其他域的网页源代码.我试过以下代码:

$('#container').load('http://google.com');

$.ajax({
    url: 'http://news.bbc.co.uk',
    type: 'GET',
    success: function(res) {
        var headline = $(res.responseText).find('a.tsh').text();
        alert(headline);
    }
});
Run Code Online (Sandbox Code Playgroud)

我仍然没有得到任何结果,只是一个空白的警报框.

ajax jquery cross-domain

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

代码在jsFiddle上工作正常但在本地系统上没有

这段代码在jsFiddle上正常工作,但在我的系统上却没有. 的jsfiddle

我已经从草稿中检查了(在jsFiddle上按Ctrl + Shift + Enter键),将此代码添加到head部分并修改如下:

window.addEvent('load', function() {
    window.webkitRequestFileSystem(window.TEMPORARY, 2*1024*1024, function(fs) {
        fs.root.getFile('test', {create: true}, function(fileEntry) {
            alert(fileEntry.toURL());
            fileEntry.createWriter(function(fileWriter) {
                var builder = new WebKitBlobBuilder();
                builder.append("Saurabh");
                builder.append("\n");
                builder.append("Saxena");

                var blob = builder.getBlob('text/plain');

                fileWriter.onwriteend = function() {
                    // navigate to file, will download
                    location.href = fileEntry.toURL();
                };
                fileWriter.write(blob);
            }, function() {});
        }, function() {});
    }, function() {});
});
Run Code Online (Sandbox Code Playgroud)

javascript file-io google-chrome-extension

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

如何使用JavaScript/JQuery在客户端本地创建文本文件

我希望使用javascript/jquery在我的系统上本地创建一个文本文件.

我正在尝试这个代码,但没有在我的系统上工作.

机器:Ubuntu 10.4 Chrome:14.0.835.126

window.webkitRequestFileSystem(window.TEMPORARY, 1024*1024, function(fs) {
        fs.root.getFile('~/Desktop/test.txt', {create: true}, function(fileEntry) {
            alert(fileEntry.fullPath);   //getting filepath
        }, function() {});
    }, function() {});
Run Code Online (Sandbox Code Playgroud)

javascript html5

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

window.open 无法打开两个以上的链接

根据我的要求,我需要创建一个 Google Chrome 扩展程序,只需在单个 Chrome 窗口的不同选项卡中单击一次即可打开多个链接(25 个以上)。该代码在 Chrome 18 之前一直工作正常。现在,我使用的是 chrome 24,该代码停止工作。我只是将所有链接存储在一个数组中,并使用 for 循环打开它们,如下所示:

  for(var i = 0; i<links.length; i++)
  {
    var tablink = links[i];
    if(links[i] != "")
    {
            tablink = *"somedomain"* + tablink;
        setTimeout(window.open(tablink), 500);  
    }
  }  
Run Code Online (Sandbox Code Playgroud)

结果,只有两个链接在选项卡中打开,其余链接将在不同的 Chrome 窗口中打开。我应该怎么做才能克服这个问题?

编辑#1

在我的清单文件中

"content_scripts": [
    {
      "matches": ["http://*/*", "https://*/*"],
      "js": ["script.js", "jquery.js", "dialog.js"]
    }
  ],


"permissions": [
    "tabs", "http://*/*", "https://*/*"
  ],
Run Code Online (Sandbox Code Playgroud)

首先给出的代码在dialog.js中

html javascript jquery google-chrome google-chrome-extension

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

在Google静态地图上创建消息气泡和路径

我正在尝试使用google maps api创建一个静态地图网址,其外观类似于以下内容

在此输入图像描述

似乎我需要增加缩放级别并向URL添加路径参数.我试图像下面这样创建网址

http://maps.googleapis.com/maps/api/staticmap?scale=4&format=png32&center=50.133751,4.833644&zoom=16&size=640x640&markers=color:red%7C50.133751,4.833644&sensor=false&path=color:blue|48.133751,4.833644|50.133751,4.833644&style=feature:road.local
Run Code Online (Sandbox Code Playgroud)

但它没有提供所需的结果,我需要根据提供的地址和lat/lng值创建动态URL.我不知何故要求以这样的方式旋转地图,以便它总是在中间有一条垂直的道路,这样我就可以在它上面绘制一条路径.另外,我需要一个气泡,它会显示达到5/1分钟的固定时间.

我现在没有使用任何编程语言.我正在尝试手动创建这些网址.

提前致谢.

编辑:我现在不需要旋转它.只想显示给定纬度/经度/地址值的1-5分钟方向,对于消息气泡,我创建了一个静态图像,我可以将其显示为叠加层.

google-maps google-maps-api-3 google-maps-static-api

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

无法在Chrome扩展程序中使用JQuery

我有一个Google Chrome扩展程序,其中我有一个background.js,我正在尝试使用JQuery.

获得以下错误.

Uncaught ReferenceError: $ is not defined
Run Code Online (Sandbox Code Playgroud)

我的清单文件代码部分

 "content_scripts": [
    {
      "matches": ["<all_urls>"],
      "js": ["script.js", "jquery.js","front.js"]
    }
  ],
  "web_accessible_resources": ["https://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js"],
  "content_security_policy": "script-src 'self' https://ajax.googleapis.com; object-src 'self'",
Run Code Online (Sandbox Code Playgroud)

我无法获得在此扩展中使用JQuery函数的任何线索.如果您需要更多理由,请告诉我.

编辑#1:清单文件

{
  "name": "Tool",
  "description": "Extension",
  "manifest_version": 2,
  "version": "5.0.0.0",
  "manifest_version": 2,
  "background": { "scripts": ["background.js"] },
  "permissions": [
    "tabs", "http://*/*", "https://*/*", "storage"
  ],
  "options_page": "options.html",
  "icons":{"16": "images/F_icon_16x16.png",
           "48": "images/F_icon_48x48.png",
          "128": "images/F_icon_128x128.png"},
  "content_scripts": [
    {
      "matches": ["<all_urls>"],
      "js": ["jquery.js", "script.js", "front.js"]
    }
  ],
  "content_security_policy": "script-src 'self' ; object-src 'self'",
  "browser_action": { …
Run Code Online (Sandbox Code Playgroud)

html jquery google-chrome google-chrome-extension

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

使用JavaScript通过单击在单个窗口上打开多个选项卡

我需要在一个窗口上打开多个选项卡,单个链接的新窗口实例不会有问题但是当涉及20+(这是我的情况)时,20多个新窗口确实是一个问题,所以我需要找到一个解决方案,代码必须只在我的情况下在chrome上运行我有35个链接存储在一个数组中.我正在使用for循环读取数组并在新选项卡中打开链接,window.open()
我只能使用JavaScript.我正在开发一个定制的chrome扩展.

我发现,当用户window.open()在谷歌浏览器的同一个窗口的不同标签中打开多个链接时,它只能成功打开前24个窗口而忽略了其余的窗口.
我需要找到一种方法,只需单击一次即可打开所有链接.

有一些谷歌Chrome扩展程序可用,像 LinkClump
此扩展程序成功打开同一窗口的不同选项卡中的所有选定链接.我正在努力修改它的工作以适应我的.

同时,如果有人能得到任何解决方案,他/她是最受欢迎的.

javascript tabs google-chrome google-chrome-extension

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

无法从localStorage访问数据

在我的内容脚本中,我完成了以下操作:

document.onreadystatechange = function(){
  localStorage["options"] = "yes";
}
Run Code Online (Sandbox Code Playgroud)

如果我尝试在我的options.html页面中访问此localStorage [“ options”]。它给了我不确定的错误。

我该怎么做才能访问此内容?

我的要求:我需要从特定页面的页面源中获取一些数据并将其存储在localStorage中。然后,我需要在options.html页面中处理这些数据。

编辑:我可以访问在后台页面的选项页面中创建的localStorage。但是我无法访问在选项页面的内容脚本中创建的localStorage。

html javascript google-chrome-extension

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

如何在 chrome 扩展中创建动态选项页面

我想用动态创建的选项创建一个选项页面。

我正在使用我的内容脚本从网页源中提取一些数据,并且我希望该数据显示在选项页面中。我怎样才能将该数据发送到我的选项页面?

我在内容脚本中使用了localStorage,但在选项页面中无法访问。

如果在选项页面中创建,则可以在后台页面和内容脚本中访问localStorage。但是,如果我在内容脚本中创建它,则无法在选项页面中访问它。

我怎样才能做到这一点?

html javascript google-chrome google-chrome-extension

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