How to save a page

Talk about add-ons and extension development.
Post Reply
User avatar
nico(at)nc
Posts: 41
Joined: March 27th, 2007, 1:50 am
Location: France
Contact:

How to save a page

Post by nico(at)nc »

Hello,

I'm adding some things to my Page Hacker extension. I would like to save the currently edited page via Javascript (and not command="Browser:SavePage" as I need to toggle contenteditable before and after saving).

I tried saveDocument(document), but it doesn't save the changes (whereas Ctrl+S or File > Save As does) and saves only html (not images and css).

Thanks for your help.
Nicolas
Bloodeye
Posts: 582
Joined: July 12th, 2004, 7:20 pm

Re: How to save a page

Post by Bloodeye »

Looks to me like "Save As" uses command Browser:SavePage. Can't you toggle
contenteditable and then call that command?

Have you looked thru other ext's like ScrapBook to see how they handle it?
User avatar
nico(at)nc
Posts: 41
Joined: March 27th, 2007, 1:50 am
Location: France
Contact:

Re: How to save a page

Post by nico(at)nc »

Thanks for your answer.

Actually, I think it is possible to call the Browser:SavePage command from a XUL element but not from javascript (as command="" is not oncommand=""). But I'm maybe wrong.

I'll have a look at ScrapBook.
Nicolas
User avatar
nico(at)nc
Posts: 41
Joined: March 27th, 2007, 1:50 am
Location: France
Contact:

Re: How to save a page

Post by nico(at)nc »

Didn't found anything interesting in ScrapBook. :(
Nicolas
Bloodeye
Posts: 582
Joined: July 12th, 2004, 7:20 pm

Re: How to save a page

Post by Bloodeye »

nico(at)nc wrote:I tried saveDocument(document), but it doesn't save the changes (whereas Ctrl+S or File > Save As does) and saves only html (not images and css).


OK this doesn't make sense since all that Save As does is invoke the Browser:SavePage command which calls the saveDocument() function.
Looking in browser.xul the only thing I see is that it uses: saveDocument(window.content.document) instead of saveDocument(document).

You might try that, otherwise look into the saveDocument function in the contentAreaUtils.js file.
http://mxr.mozilla.org/firefox/source/t ... ils.js#151
User avatar
nico(at)nc
Posts: 41
Joined: March 27th, 2007, 1:50 am
Location: France
Contact:

Re: How to save a page

Post by nico(at)nc »

Great, it is working with window.content.document: with just document the save as window did not allowed to choose between "complete web page" and "html only".

But there is not something looking like a bug: when saving as "complete" the changes are saved, and when using "html only" they are not! I'll try to find what is wrong.
Nicolas
Post Reply