Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 04-26-2008, 07:53 PM   PM User | #1
Jonathanrw
New to the CF scene

 
Join Date: Apr 2008
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
Jonathanrw is an unknown quantity at this point
Select all and copy not working help!

I am trying to get it where when you click in the text box it will select all the text and copy it to the clipboard but it only selects the text but does not copy it. Am I missing something or is part of my code wrong.

Look below at code.
Please help. Thanks!

<html>
<body>
<script type="text/javascript">
function SelectAll(id)
{
document.getElementById(id).focus();
document.getElementById(id).select();
}
</script>


<input type="text" id="direct-url17" onclick="SelectAll('direct-url17');" value="Text which I am trying to get copied." size="38" onclick="highlight(getElementById('direct-url')); APITrack('copy_details_url');" title="Click to Copy" name="T14"/><font color="#FF0000" size="2"><u>Click in box to copy.<br></u></font>



</body>
</html>
Jonathanrw is offline   Reply With Quote
Old 04-26-2008, 07:58 PM   PM User | #2
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Code:
<span id="copytext" style="height:120;width:200;background-color:teal">
This text will be copied onto the clipboard when you click the button below.
</span>

<textarea id="holdtext" style ="display:none;"></textarea>
<br><br>
<input type = "button" onClick="ClipBoard();" value = "Copy to Clipboard"</button> 

<script type = "text/javascript">

function ClipBoard() {
holdtext.innerText = copytext.innerText;
Copied = holdtext.createTextRange();
Copied.execCommand("RemoveFormat");
Copied.execCommand("Copy");
window.status="Contents copied to clipboard"
setTimeout("window.status=''",2500)
}

</script>
Philip M is offline   Reply With Quote
Old 04-27-2008, 04:36 AM   PM User | #3
A1ien51
Senior Coder

 
A1ien51's Avatar
 
Join Date: Jun 2002
Location: Between DC and Baltimore In a Cave
Posts: 2,717
Thanks: 1
Thanked 94 Times in 88 Posts
A1ien51 will become famous soon enough
FYI: Browsers have a setting to disable copying and reading values from the clipboard.

Eric
__________________
Tech Author [Ajax In Action, JavaScript: Visual Blueprint]
A1ien51 is offline   Reply With Quote
Old 04-27-2008, 07:49 AM   PM User | #4
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by A1ien51 View Post
FYI: Browsers have a setting to disable copying and reading values from the clipboard.

Eric
I don't find this in IE6. Could you direct me to the appropriate setting?
Philip M is offline   Reply With Quote
Old 04-27-2008, 03:11 PM   PM User | #5
A1ien51
Senior Coder

 
A1ien51's Avatar
 
Join Date: Jun 2002
Location: Between DC and Baltimore In a Cave
Posts: 2,717
Thanks: 1
Thanked 94 Times in 88 Posts
A1ien51 will become famous soon enough
IE started it in IE7 since reading and writing to the clipboard can be a security risk for those that copy sensitive material to the clipboard.

Eric
__________________
Tech Author [Ajax In Action, JavaScript: Visual Blueprint]
A1ien51 is offline   Reply With Quote
Old 04-27-2008, 03:28 PM   PM User | #6
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,044
Thanks: 197
Thanked 2,412 Times in 2,390 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Thanks for the info. As I see it this security feature is included in IE7 only and prevents programmatic reading from the clipboard, as opposed to writing or copying to it.

The default option is Prompt, but the feature can be completely disabled, or the user can choose to allow programmatic clipboard access to internet trusted zones only.
Philip M is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

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

Forum Jump


All times are GMT +1. The time now is 01:37 AM.


Advertisement
Log in to turn off these ads.