3

I'm thinking about writing a Chrome extension that will need to, on a certain dynamic page of a certain site, grab a few links and analyze the contents of the linked pages.

I actually don't know much about writing browser extensions, so I wanted to see if it was doable before I committed myself to learning how. I do know that extensions typically execute Javascript but I am unaware of how to get that sort of result with Javascript.

Georg Fritzsche
  • 97,545
  • 26
  • 194
  • 236
Arcturus
  • 73
  • 1
  • 4

2 Answers2

0

Use jquery ajax to fetch the content of other pages.

Wouter Dorgelo
  • 11,770
  • 11
  • 62
  • 80
Tschallacka
  • 27,901
  • 14
  • 88
  • 133
0

You can use jQuery and this plugin by James Padolsey to make a cross domain request; the plugin will return the page contents. You can then do something like this to get it into a jQuery object:

$.ajax({
    url: 'http://example.com',
    type: 'GET',
    success: function(res) {
        var contents = $(res.responseText);
    }
});

With that contents object you can do anything you would do normally with a jQuery object, such as find(). For instance, if you wanted to get the title of the page, you could do:

$.ajax({
    url: 'http://example.com',
    type: 'GET',
    success: function(res) {
        var contents = $(res.responseText);
        var title = contents.find('title').text();
    }
});
angus
  • 128
  • 1
  • 1
  • 5
  • 4
    Chrome extensions can perform [cross-domain requests](http://code.google.com/chrome/extensions/xhr.html) via host permsiions; no jQuery plugin required. – apsillers Jul 16 '12 at 00:31