"window.open" from selection WITH formatting

M

melvynm

Currently I'm trying to make a plugin for my browser (Maxthon/IE6)
which allows me to select any text on the current page and press the
plugin button to create a new tab with the selection.

This will do the job:
<script language="JavaScript">
javascript:r4NSy3m=document.selection.createRange();oDgs2Ke=r4NSy3m.text;dT30FfN=new
Date();wdGs8c6=window.open('','w'+dT30FfN.getTime(),'');wdGs8c6.document.write(oDgs2Ke);
void(wdGs8c6.document.close())
</script>

Unfortunately, I want to retain the layout of the text and the above
code strips it out.
The code on http://www.webreference.com/js/column12/crossbrowser.html
seems to do precisely what I want but it displays the current selection
in a box on the page. I'm not interested in using 'onmouseup' as I want
to decide when the page should open.

Can someone please show me how to make the webreference example work in
a new page on demand.
 
M

Martin Honnen

Currently I'm trying to make a plugin for my browser (Maxthon/IE6)
which allows me to select any text on the current page and press the
plugin button to create a new tab with the selection.

This will do the job:
<script language="JavaScript">
javascript:r4NSy3m=document.selection.createRange();oDgs2Ke=r4NSy3m.text;dT30FfN=new
Date();wdGs8c6=window.open('','w'+dT30FfN.getTime(),'');wdGs8c6.document.write(oDgs2Ke);
void(wdGs8c6.document.close())
</script>

Unfortunately, I want to retain the layout of the text and the above
code strips it out.

var range = document.selection.createRange();
var html = range.htmlText;
var win = window.open('', 'w' + new Date().getTime());
win.document.open();
win.document.write(html);
win.document.close();
void 0

is probably what you are after, put on one line in a javascript:
bookmark of course.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Similar Threads


Members online

No members online now.

Forum statistics

Threads
473,951
Messages
2,570,113
Members
46,698
Latest member
alexxx

Latest Threads

Top