"window.open" from selection WITH formatting

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • melvynm@gmail.com

    "window.open" from selection WITH formatting

    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="JavaS cript">
    javascript:r4NS y3m=document.se lection.createR ange();oDgs2Ke= r4NSy3m.text;dT 30FfN=new
    Date();wdGs8c6= window.open('', 'w'+dT30FfN.get Time(),'');wdGs 8c6.document.wr ite(oDgs2Ke);
    void(wdGs8c6.do cument.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/colum...ssbrowser.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.

  • Martin Honnen

    #2
    Re: &quot;window.op en&quot; from selection WITH formatting



    melvynm@gmail.c om wrote:
    [color=blue]
    > 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="JavaS cript">
    > javascript:r4NS y3m=document.se lection.createR ange();oDgs2Ke= r4NSy3m.text;dT 30FfN=new
    > Date();wdGs8c6= window.open('', 'w'+dT30FfN.get Time(),'');wdGs 8c6.document.wr ite(oDgs2Ke);
    > void(wdGs8c6.do cument.close())
    > </script>
    >
    > Unfortunately, I want to retain the layout of the text and the above
    > code strips it out.[/color]

    var range = document.select ion.createRange ();
    var html = range.htmlText;
    var win = window.open('', 'w' + new Date().getTime( ));
    win.document.op en();
    win.document.wr ite(html);
    win.document.cl ose();
    void 0

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

    --

    Martin Honnen

    Comment

    • melvynm@gmail.com

      #3
      Re: &quot;window.op en&quot; from selection WITH formatting

      Beautiful - thank you so much.

      Comment

      Working...