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.
How to save a page
- nico(at)nc
- Posts: 41
- Joined: March 27th, 2007, 1:50 am
- Location: France
- Contact:
How to save a page
Nicolas
-
- Posts: 582
- Joined: July 12th, 2004, 7:20 pm
Re: How to save a page
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?
contenteditable and then call that command?
Have you looked thru other ext's like ScrapBook to see how they handle it?
- nico(at)nc
- Posts: 41
- Joined: March 27th, 2007, 1:50 am
- Location: France
- Contact:
Re: How to save a page
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.
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
- Posts: 41
- Joined: March 27th, 2007, 1:50 am
- Location: France
- Contact:
-
- Posts: 582
- Joined: July 12th, 2004, 7:20 pm
Re: How to save a page
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
- Posts: 41
- Joined: March 27th, 2007, 1:50 am
- Location: France
- Contact:
Re: How to save a page
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.
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