473,396 Members | 1,990 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

Bookmarklet copy & paste that preserves formatting

Hi,

I would like to add a submission bookmarklet to my app that takes the
current selection and pastes it into the app's rich text editor while
preserving formatting. It should work in at least Firefox & IE.

Any pointers on how this could be done? Are there any examples that I
can look at?

Amir

Jun 5 '07 #1
7 2736
On Jun 5, 3:25 pm, Amir Michail <amich...@gmail.comwrote:
Hi,

I would like to add a submission bookmarklet to my app that takes the
current selection and pastes it into the app's rich text editor while
preserving formatting. It should work in at least Firefox & IE.

use
getSelection().getRangeAt(0).cloneContents();
to clone the contents of current selection then append it to your rte.

if you want the HTML then append the cloned contents to an element
(e.g. div) and use innerHTML property to get the HTML

Jun 6 '07 #2
scripts.contact wrote:
On Jun 5, 3:25 pm, Amir Michail <amich...@gmail.comwrote:
>Hi,

I would like to add a submission bookmarklet to my app that takes the
current selection and pastes it into the app's rich text editor while
preserving formatting. It should work in at least Firefox & IE.


use
getSelection().getRangeAt(0).cloneContents();
to clone the contents of current selection then append it to your rte.

if you want the HTML then append the cloned contents to an element
(e.g. div) and use innerHTML property to get the HTML
OK, since *you* brought it up. ;)

Can you explain what the hell a range is for?

Why would you need to addRange?

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
Jun 7 '07 #3
-Lost wrote:
scripts.contact wrote:
>On Jun 5, 3:25 pm, Amir Michail <amich...@gmail.comwrote:
>>Hi,

I would like to add a submission bookmarklet to my app that takes the
current selection and pastes it into the app's rich text editor while
preserving formatting. It should work in at least Firefox & IE.


use
getSelection().getRangeAt(0).cloneContents();
to clone the contents of current selection then append it to your rte.

if you want the HTML then append the cloned contents to an element
(e.g. div) and use innerHTML property to get the HTML

OK, since *you* brought it up. ;)

Can you explain what the hell a range is for?

Why would you need to addRange?
I have thought on this some, and think I may have an example of its usage.

Let's say you provide the user with the ability to click multiple
paragraphs and do something with them.

You would need to addRange on a per-paragraph basis, right?

Jeez, I gotta' stop replying to myself.

--
-Lost
Remove the extra words to reply by e-mail. Don't e-mail me. I am
kidding. No I am not.
Jun 7 '07 #4
On Jun 5, 3:25 pm, Amir Michail <amich...@gmail.comwrote:
Hi,

I would like to add a submission bookmarklet to my app that takes the
current selection and pastes it into the app's rich text editor while
preserving formatting. It should work in at least Firefox & IE.
use
var c=getSelection().getRangeAt(0).cloneContents();
method to clone the contents of current selection then append it
anywhere using appendChild(c).

If you wand to get the HTML of selection then just append the content
in a DIV and use innerHTML property

Jun 8 '07 #5
On Jun 8, 5:20 am, "scripts.contact" <scripts.cont...@gmail.com>
wrote:
On Jun 5, 3:25 pm, Amir Michail <amich...@gmail.comwrote:
Hi,
I would like to add a submission bookmarklet to my app that takes the
current selection and pastes it into the app's rich text editor while
preserving formatting. It should work in at least Firefox & IE.

use
var c=getSelection().getRangeAt(0).cloneContents();
method to clone the contents of current selection then append it
anywhere using appendChild(c).

If you wand to get the HTML of selection then just append the content
in a DIV and use innerHTML property
I still don't understand the mechanism for copying the selection to
a RichTextArea widget in a gwt app via a bookmarklet.

Clicking on a bookmarklet normally redirects to an app url along with
some additional parameters added.

So maybe I need to get the selection as html first and add that html
to the
end of the url? Or is there some other way?

Amir

Jun 8 '07 #6
On Jun 8, 7:30 am, Amir Michail <amich...@gmail.comwrote:
>
I still don't understand the mechanism for copying the selection to
a RichTextArea widget in a gwt app via a bookmarklet.
try this :
<script>
function copyCont(){
var ifr=document.getElementById("s");

ifr.contentDocument.body.appendChild(getSelection( ).getRangeAt(0).cloneContents())
}
</script>
<iframe id="s" onload="this.contentDocument.designMode='on';"></
iframe>
<div>content<bcontent</b<icontent</i></div>
<button onclick="copyCont()">Copy contents of selection in IFRAME</
button>
Clicking on a bookmarklet normally redirects to an app url along with
some additional parameters added.

So maybe I need to get the selection as html first and add that html
to the
end of the url? Or is there some other way?

what is the URL ?

Jun 8 '07 #7
On Jun 8, 3:35 pm, "scripts.contact" <scripts.cont...@gmail.com>
wrote:
On Jun 8, 7:30 am, Amir Michail <amich...@gmail.comwrote:
I still don't understand the mechanism for copying the selection to
a RichTextArea widget in a gwt app via a bookmarklet.

try this :
<script>
function copyCont(){
var ifr=document.getElementById("s");

ifr.contentDocument.body.appendChild(getSelection( ).getRangeAt(0).cloneContents())
}
</script>
<iframe id="s" onload="this.contentDocument.designMode='on';"></
iframe>
<div>content<bcontent</b<icontent</i></div>
<button onclick="copyCont()">Copy contents of selection in IFRAME</
button>
The gwt app may not be open when the user clicks on the bookmarklet.

Moreover, if the bookmarklet opens it and tries to access the rich
text editor therein, won't that be a security violation?
Clicking on a bookmarklet normally redirects to an app url along with
some additional parameters added.
So maybe I need to get the selection as html first and add that html
to the
end of the url? Or is there some other way?

what is the URL ?
This is for my Study Stickies gwt app:

http://studystickies.com

Currently, the bookmarklets look like this (but they do not preserve
formatting in selections):

Add Resource
============

javascript:t=document.title;u=document.location.hr ef;s=(document.getSelection)?
document.getSelection():document.selection.createR ange().text;location.href='http://
studystickies.com#?cmd=add_resource&title=' + encodeURIComponent(t)
+'&url='+encodeURIComponent(u)+'&selection='+encod eURIComponent(s);

Add Sticky
==========

javascript:t=document.title;u=document.location.hr ef;s=(document.getSelection)?
document.getSelection():document.selection.createR ange().text;location.href='http://
studystickies.com#?cmd=add_sticky&title=' + encodeURIComponent(t)
+'&url='+encodeURIComponent(u)+'&selection='+encod eURIComponent(s);

Amir

Jun 8 '07 #8

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Tomomichi Amano | last post by:
Hello. I was wondering how to paste-copy-cut-delete at a SELECTED SPOT in a textBox. Thanks in advance.
3
by: Rachel Suddeth | last post by:
This may not be the right forum, but it's a problem I chiefly come across when trying to post here. When I do a copy/paste from VS, the text always looks really weird (and even if I'm in an...
2
by: Mansi | last post by:
I'm trying to automate excel from c#. One of the things I need to do is to copy/paste/insert rows in excel via c# code. I tried to do the following: 1) Select a row in excel (a12 to k12) 2)...
6
by: NuB | last post by:
I have a winform and a menu on the form, It allows the users to copy and paste text from text boxes. I never had to do this before, how can I copy and paste text from one box to another?
2
by: al_johnson222 | last post by:
>From any page, I want to be able to call a JS function that will do the equivelant of select all, and copy. This data will then be posted to a page that will log it. This would be easy using...
1
by: Grant Smith | last post by:
I've got an application that I can copy some text out of the RichTextBox control. I would like to keep the formatting so I'm able to copy it to the Clipboard with RTF formatting. I have no...
0
by: Tom | last post by:
When I use ctrl-c to copy and ctrl-v to paste from a RichTextBox into NotePad ... I get nice ASCII text with the proper returns. Everything looks good. When I paste into WordPad ... I get the...
2
by: deve8ore | last post by:
Hello, I'm working with Adobe Reader 8.0, working on a project for work, so not allowed to download any other software/ freeware. We receive PDF files frequently with about 20 sheets. I'd like...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.