English 中文(简体)
从选定表格中找到 html
原标题:Get html from a selected tab [closed]

因此,我想在一家报社时获得一个选定的表格的html。 但是,有些工作要做。 什么是失踪?

mani.4/1999/.json

{
  "name": "extension",
  "version": "1.0",
  "description": "discription",
  "content_scripts": [
    {
      "matches": ["http://www.google.com/*"],
      "js": ["contentscript.js"]
    }
  ],
  "browser_action": {
    "default_icon": "icon.png",
    "popup": "popup.html"
  },
  "permissions": [
    "http://ajax.googleapis.com/",
    "tabs"
  ]
}

popup.html

<html>
<head>
<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.4.2/jquery.min.js"> </script>
</head>
<body>
<script>

function getHTML()
{

chrome.tabs.getSelected(null, function(tab) {
    chrome.tabs.sendRequest(tab.id, {method: "getHTML"}, function(response) {
        if(respond.method="getHTML"){               
            alert(response.html);  
      }
    });
});

}
</script>
 <input type="submit" value="OK" onclick ="getHTML()" />
</body>

contentscript.js

chrome.extension.onRequest.addListener(
    function(request, sender, sendResponse) {
        if(request.method == "getHTML"){
            sendResponse({html: document.all[0].outerHTML});
        }
    }
);
最佳回答

I see two errors: 1) popup.html is checking for "respond" instead of "response". 2) popup.html is checking for response.method to be "getHTML", but the content_script never sets the "method" field.

问题回答

document.all/code> is un Defin in Mitchell!

Replace it with document.getElementsByTagName("html")[0].innerHTML:

chrome.extension.onRequest.addListener(
    function(request, sender, sendResponse) {
        if(request.method == "getHTML"){
            sendResponse({html: document.getElementsByTagName("html")[0].innerHTML});
        }
    }
);




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!