Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 6 of 6
  1. #1
    New to the CF scene
    Join Date
    Apr 2008
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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>

  • #2
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,247
    Thanks
    203
    Thanked 2,555 Times in 2,533 Posts
    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>

  • #3
    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
    FYI: Browsers have a setting to disable copying and reading values from the clipboard.

    Eric
    Tech Author [Ajax In Action, JavaScript: Visual Blueprint]

  • #4
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,247
    Thanks
    203
    Thanked 2,555 Times in 2,533 Posts
    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?

  • #5
    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
    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]

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    18,247
    Thanks
    203
    Thanked 2,555 Times in 2,533 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •