onclick select/copy for textarea or forms

Discussion in 'JavaScript' started by monkeyclap, Feb 9, 2010.

  1. #1
    but is there anything like this for blockquotes?
     
    monkeyclap, Feb 9, 2010 IP
  2. wing

    wing Active Member

    Messages:
    210
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    58
    #2
    Yes, this is a function originally written by Mark Honnen that does the job.

    
    
    <script language=javascript>
      /**
       * Creates a selection on any passed html element
       *
       * @author Mark Honnen 
       * @param p_oDomObject  - a DOM object
       * @return Always false
       */
      function selectElm (p_oDomObject) {
          var sel, rng, doc, win;
    
          if ((doc = p_oDomObject.ownerDocument) 
          && (win = doc.defaultView) 
          && 'undefined' != typeof win.getSelection 
          && typeof doc.createRange !='undefined' 
          && (sel = window.getSelection())
          && typeof sel.removeAllRanges != 'undefined') {
              rng = doc.createRange();
              rng.selectNode(p_oDomObject);
              sel.removeAllRanges();
              sel.addRange(rng);
          } else if (document.body && typeof document.body.createTextRange != 'undefined' && (rng = document.body.createTextRange())) {
              rng.moveToElementText(p_oDomObject);
              rng.select();
          }
          
         return false;
      }
    
    </script>
    
    <blockquote onclick="selectElm(this)">
    Here is a quotation Here is a quotation Here is a quotation 
    </blockquote>
    
    
    Code (markup):
    :)
     
    wing, Feb 9, 2010 IP
    monkeyclap likes this.
  3. monkeyclap

    monkeyclap Active Member

    Messages:
    836
    Likes Received:
    6
    Best Answers:
    0
    Trophy Points:
    85
    #3
    hi, works a treat and selects beautifully.

    i'm assuming there's no way for it to autocopy upon click?

    thanks again
     
    Last edited: Feb 10, 2010
    monkeyclap, Feb 10, 2010 IP
  4. wing

    wing Active Member

    Messages:
    210
    Likes Received:
    14
    Best Answers:
    0
    Trophy Points:
    58
    #4
    It's possible, you need a .swf file working as a transportation helper though, to make it work with Firefox.
    A working example is in the zip file.
     

    Attached Files:

    wing, Feb 10, 2010 IP