MozillaZine

How to save a page

Talk about add-ons and extension development.
nico(at)nc

User avatar
 
Posts: 41
Joined: March 27th, 2007, 1:50 am
Location: France

Post Posted August 23rd, 2008, 9:38 am

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

Post Posted August 27th, 2008, 8:01 am

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?

nico(at)nc

User avatar
 
Posts: 41
Joined: March 27th, 2007, 1:50 am
Location: France

Post Posted August 27th, 2008, 9:33 am

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

nico(at)nc

User avatar
 
Posts: 41
Joined: March 27th, 2007, 1:50 am
Location: France

Post Posted August 29th, 2008, 2:26 pm

Didn't found anything interesting in ScrapBook. :(
Nicolas

Bloodeye
 
Posts: 582
Joined: July 12th, 2004, 7:20 pm

Post Posted August 30th, 2008, 6:29 am

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

nico(at)nc

User avatar
 
Posts: 41
Joined: March 27th, 2007, 1:50 am
Location: France

Post Posted August 30th, 2008, 9:38 am

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

Return to Extension Development


Who is online

Users browsing this forum: No registered users and 1 guest