Tycoon Talk
Become a Big fish!
The number 1 forum for online business!
Post topics, ask questions, share your knowledge.
Tycoon Talk is part of Freelancer.com - find skilled workers online at a fraction of the cost.

JavaScript Forum


You are currently viewing our JavaScript Forum as a guest. Please register to participate.
Login



Reply
Copy Content of Div or Span with Javascript
Old 07-15-2008, 04:52 PM Copy Content of Div or Span with Javascript
aschecht's Avatar
Extreme Talker

Posts: 190
Name: A
Location: San Jose, CA
Trades: 6
I'm using a Javascript that allows users to click a button on my site which copies any selected content to the clipboard.

I'm wondering if it's possible to save a step so that the Javascript allows them to click on any text content on the webpage and, with the click, have the content in the div or span they're clicking on copied to the clipboard?

In other words, I want to save them the trouble of highlighting the content and then clicking the button. I want them, just by clicking on a word in that div or span to have it select all the content of that div/span and copy it to the clipboard.

Can it be done?

Andrew
aschecht is offline
Reply With Quote
View Public Profile Visit aschecht's homepage!
 
 
Register now for full access!
Old 07-15-2008, 05:30 PM Re: Copy Content of Div or Span with Javascript
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
http://www.htmlgoodies.com/beyond/ja...le.php/3458851
http://www.dynamicdrive.com/dynamicindex11/copytext.htm

Although it will only work in IE and possibly Opera
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 07-15-2008, 06:35 PM Re: Copy Content of Div or Span with Javascript
aschecht's Avatar
Extreme Talker

Posts: 190
Name: A
Location: San Jose, CA
Trades: 6
Thanks for the quick reply, Chris. It doesn't look like either of those scripts will exactly fit the bill for me. Here's an example of one of the pages I'd like to implement this on:
http://www.icdmeister.com/site/Codes...ential_HTN.htm
I want users to be able to click on any of the red numbers and have that click select and copy the full text in that particular <span>

The first script (http://www.htmlgoodies.com/beyond/ja...le.php/3458851)
allows one to click a button to copy all the text in a pre-defined area. It doesn't use the click to determine which area/content is copied from.

The second script
(http://www.dynamicdrive.com/dynamicindex11/copytext.htm)
gets rid of the button but still requires the selection of text by dragging the mouse. I'd like to be able to select that text just by clicking anywhere within that span or div's text.

My current copy to clipboard script works with IE and FF so I'm hoping I'll be able to adapt it to maintain compatibility with both browsers.

I guess a more general question is: Is it possible to select the content in a div/span by clicking on it or does selection require either dragging over the area with the mouse or having it in a pre-defined content area?

Andrew
aschecht is offline
Reply With Quote
View Public Profile Visit aschecht's homepage!
 
Old 07-15-2008, 11:19 PM Re: Copy Content of Div or Span with Javascript
chrishirst's Avatar
Missing! presumed drunk.

Posts: 42,383
Name: Chris Hirst
Location: Blackpool. UK
Trades: 0
to get the content of a particular element use this.innerHTML in an onclick event and pass it to your script
__________________
Chris. ->>
Please login or register to view this content. Registration is FREE
<<-

A foolish consistency is the hobgoblin of little minds
Thought for today:- Is SEO the only industry where all the cowboys are Indians?
chrishirst is online now
Reply With Quote
View Public Profile Visit chrishirst's homepage!
 
Old 07-16-2008, 01:25 AM Re: Copy Content of Div or Span with Javascript
aschecht's Avatar
Extreme Talker

Posts: 190
Name: A
Location: San Jose, CA
Trades: 6
Thanks Chris. It looks like what I want to do will be possible with just some small modifications to my original Copy to Clipboard script.

Thanks for pointing me towards this.innerHTML. Looks like it should do the trick.

Andrew
aschecht is offline
Reply With Quote
View Public Profile Visit aschecht's homepage!
 
Reply     « Reply to Copy Content of Div or Span with Javascript
 

Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are Off
Pingbacks are Off
Refbacks are Off





   
RSS Feed  Feeds: RSS   JS   XML
RSS Feed  Feeds for this forum: RSS   JS   XML



Page generated in 0.21547 seconds with 12 queries