Do you Java-script?
September 16, 2009 9:06 AM
Calling all Javascript Experts: I am trying to tweak a small javascript bookmarklet to improve its functionality. The fact I dont know HOW is turning out to be a bit of a challenge. Help me please!
javascript:void(location.href='http://html-pdf-converter.com/en/convert?u='+escape(location.href))
This bookmarklet opens the webpage of html-pdf-converter but I want it to to open a new page and load the url where I am when I click on the bookmarklet. (I know it can be done because my other favourite bookmarklet does it for a different purpose) see code here:
javascript:popw='';Q='';x=document;y=window;if(x.selection)%20{Q=x.selection.createRange().text;}%20else%20if%20(y.getSelection)%20{Q=y.getSelection();}%20else%20if%20(x.getSelection)%20{Q=x.getSelection();}popw%20=%20y.open('https://mail.google.com/a/xxxx.comk/?view=cm&fs=1&tf=1&to=&su='%20+%20escape(document.title)%20+%20'&body='%20+%20escape(Q)%20+%20escape('\n')%20+%20escape(location.href)%20+%20'&bcc='%20+%20escape("xxxx@xxxx.com")%20+%20'&zx=RANDOMCRAP&shva=1&disablechatbrowsercheck=1&ui=1','gmailForm','scrollbars=yes,width=680,height=510,top=175,left=75,status=no,resizable=yes');if%20(!document.all)%20T%20=%20setTimeout('popw.focus()',50);void(0);
Now if only I can get someone to help me pick the best bits from both and make it work.
EXTRA points, if someone can also get it to press the 'convert' button so all I get is a save/open dialogue.
In case you are wondering, I have tried using software on my computer to convert like cutepdf but the output is not nearly as good as this.
Many thanks
javascript:void(location.href='http://html-pdf-converter.com/en/convert?u='+escape(location.href))
This bookmarklet opens the webpage of html-pdf-converter but I want it to to open a new page and load the url where I am when I click on the bookmarklet. (I know it can be done because my other favourite bookmarklet does it for a different purpose) see code here:
javascript:popw='';Q='';x=document;y=window;if(x.selection)%20{Q=x.selection.createRange().text;}%20else%20if%20(y.getSelection)%20{Q=y.getSelection();}%20else%20if%20(x.getSelection)%20{Q=x.getSelection();}popw%20=%20y.open('https://mail.google.com/a/xxxx.comk/?view=cm&fs=1&tf=1&to=&su='%20+%20escape(document.title)%20+%20'&body='%20+%20escape(Q)%20+%20escape('\n')%20+%20escape(location.href)%20+%20'&bcc='%20+%20escape("xxxx@xxxx.com")%20+%20'&zx=RANDOMCRAP&shva=1&disablechatbrowsercheck=1&ui=1','gmailForm','scrollbars=yes,width=680,height=510,top=175,left=75,status=no,resizable=yes');if%20(!document.all)%20T%20=%20setTimeout('popw.focus()',50);void(0);
Now if only I can get someone to help me pick the best bits from both and make it work.
EXTRA points, if someone can also get it to press the 'convert' button so all I get is a save/open dialogue.
In case you are wondering, I have tried using software on my computer to convert like cutepdf but the output is not nearly as good as this.
Many thanks
I would try
posted by kmz at 9:23 AM on September 16, 2009
javascript:void(window.open('http://html-pdf-converter.com/en/convert?u='+escape(location.href)))
.posted by kmz at 9:23 AM on September 16, 2009
KMZ, I see what you tried there but sadly it still does the same thing and ignores the window.open command. Any ideas on how we can use 'popw' which appears in the other example?
posted by london302 at 9:32 AM on September 16, 2009
posted by london302 at 9:32 AM on September 16, 2009
popw there is a variable which actually gets assigned by window.open. I'm not sure why it's not working for you. It seems to be working here, though I haven't tried it in bookmarklet form. What browser are you using?
posted by kmz at 9:34 AM on September 16, 2009
posted by kmz at 9:34 AM on September 16, 2009
javascript:void(window.open('http://html-pdf-converter.com/en/convert?u='+escape(location.href)))
posted by bitdamaged at 9:48 AM on September 16, 2009
posted by bitdamaged at 9:48 AM on September 16, 2009
doh I did kmz. That worked for me.
posted by bitdamaged at 9:53 AM on September 16, 2009
posted by bitdamaged at 9:53 AM on September 16, 2009
Make sure your popup blocker is off London.
The following code opens your current location in a new window, and then creates a PDF. It works for me as a bookmarklet.
javascript:var win;win=window.open('http://html-pdf-converter.com/en/convert?u='+escape(location.href)); win.document.onload="document.getElementById('form_html_to_pdf').submit()";
posted by trueluk at 12:17 PM on September 16, 2009
The following code opens your current location in a new window, and then creates a PDF. It works for me as a bookmarklet.
javascript:var win;win=window.open('http://html-pdf-converter.com/en/convert?u='+escape(location.href)); win.document.onload="document.getElementById('form_html_to_pdf').submit()";
posted by trueluk at 12:17 PM on September 16, 2009
thanks all for your input.
Trueluk, your code does exactly as you say. One thing worth noting however: the original page ends up with the following text:
document.getElementById('form_html_to_pdf').submit()
any way of fixing this?
thanks very much kmz, bitdamaged and trueluk
posted by london302 at 3:33 PM on September 16, 2009
Trueluk, your code does exactly as you say. One thing worth noting however: the original page ends up with the following text:
document.getElementById('form_html_to_pdf').submit()
any way of fixing this?
thanks very much kmz, bitdamaged and trueluk
posted by london302 at 3:33 PM on September 16, 2009
javascript:(function(){var win;win=window.open('http://html-pdf-converter.com/en/convert?u='+escape(location.href)); win.document.onload=function(){document.getElementById('form_html_to_pdf').submit();};})();
posted by bbyboi at 2:47 AM on September 17, 2009
posted by bbyboi at 2:47 AM on September 17, 2009
.bbyboi: Thanks/ This is very fast and does the job well . Any way it could open the pdf converter page in a new tab?
posted by london302 at 4:58 AM on September 17, 2009
posted by london302 at 4:58 AM on September 17, 2009
This thread is closed to new comments.
posted by london302 at 9:07 AM on September 16, 2009