0

I'm writing an extension for Google Chrome that converts a webpage to a PDF document. I'm adding this functionality for Context Menus as well. It is pretty simple to get the DOM of the current webpage, but I'm trying to add a functionality to convert a link to a PDF document. SO, when the user right-clicks a link, and clicks on "Convert Link Target to PDF," the plugin should convert the webpage at link target to a PDF document. To be able to do this, I need to get the DOM of the link target. How can I do this? I couldn't come across any JavaScript API that given the link/URL, returns the DOM, or any Chrome-Extension-API that does a similar functionality. The data is being passed to an NPAPI DLL, so if there is any API that I could use in the DLL to perform the above functionality, please do mention it.

Rahul Gulati
  • 363
  • 1
  • 4
  • 16

1 Answers1

2

Get the page using XMLHttpRequest and then convert it to a dom using....
JavaScript DOMParser access innerHTML and other properties

Community
  • 1
  • 1
PAEz
  • 8,366
  • 2
  • 34
  • 27
  • 1
    By setting the `responseType` property of the `XMLHttpRequest` instance to `"document"`, the `.response` property of the XHR instance will contain the DOM of the returned document. http://jsfiddle.net/YDDV4/ [Supported](https://developer.mozilla.org/en/XMLHttpRequest#Browser_compatibility) as of Firefox 11 and Chrome 18. – Rob W Apr 13 '12 at 16:09
  • Could you show me an example as to how can I get the innerHTML of the link that is clicked? – Rahul Gulati Apr 16 '12 at 16:44