Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. Make a TEXT SELECTION

Make a TEXT SELECTION

Scheduled Pinned Locked Moved Web Development
javascriptquestion
8 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • A Offline
    A Offline
    Armando_Ramirez
    wrote on last edited by
    #1

    I have text in my webpage and I want to make a simple Buton that on click : selects, copy all the text on clipboard, and finally deselects all or at least just selects all I think it´s very simple using JavaScript but I cant get it any comments ? THANX ¡¡¡ Armando Monterrey, Mexico

    E C B 3 Replies Last reply
    0
    • A Armando_Ramirez

      I have text in my webpage and I want to make a simple Buton that on click : selects, copy all the text on clipboard, and finally deselects all or at least just selects all I think it´s very simple using JavaScript but I cant get it any comments ? THANX ¡¡¡ Armando Monterrey, Mexico

      E Offline
      E Offline
      enjoycrack
      wrote on last edited by
      #2

      Hi there, IMO, just simple getting the selected text from the textbox control and do paste the selected text into clipboard by using this statement window.clipboardData.setData("Text",selectedText); << >>

      A 1 Reply Last reply
      0
      • A Armando_Ramirez

        I have text in my webpage and I want to make a simple Buton that on click : selects, copy all the text on clipboard, and finally deselects all or at least just selects all I think it´s very simple using JavaScript but I cant get it any comments ? THANX ¡¡¡ Armando Monterrey, Mexico

        C Offline
        C Offline
        Curtis Schlak
        wrote on last edited by
        #3

        I hate Internet-Explorer-only solutions; however, here's one for you:

        var r = document.body.createTextRange();
        r.select();
        r.execCommand( "copy" );

        If you want a cross-browser implementation, may I suggest reading the innerHTML property of document.body and using regular expressions to remove any tags. "we must lose precision to make significant statements about complex systems." -deKorvin on uncertainty

        1 Reply Last reply
        0
        • E enjoycrack

          Hi there, IMO, just simple getting the selected text from the textbox control and do paste the selected text into clipboard by using this statement window.clipboardData.setData("Text",selectedText); << >>

          A Offline
          A Offline
          Armando_Ramirez
          wrote on last edited by
          #4

          I tried by using this " onClick="javascript:select();" " but it only selects the text that is into the button not the text on the webpage And I didnt get the idea you gave me so could you give another one using my example?

          E 1 Reply Last reply
          0
          • A Armando_Ramirez

            I tried by using this " onClick="javascript:select();" " but it only selects the text that is into the button not the text on the webpage And I didnt get the idea you gave me so could you give another one using my example?

            E Offline
            E Offline
            enjoycrack
            wrote on last edited by
            #5

            where is the text you put it into (textbox or textarea control)? or do you want to copy whole page? << >>

            A 1 Reply Last reply
            0
            • E enjoycrack

              where is the text you put it into (textbox or textarea control)? or do you want to copy whole page? << >>

              A Offline
              A Offline
              Armando_Ramirez
              wrote on last edited by
              #6

              I want to copy the whole page, My page doesnt have any pics, only text thanx ¡

              E 1 Reply Last reply
              0
              • A Armando_Ramirez

                I have text in my webpage and I want to make a simple Buton that on click : selects, copy all the text on clipboard, and finally deselects all or at least just selects all I think it´s very simple using JavaScript but I cant get it any comments ? THANX ¡¡¡ Armando Monterrey, Mexico

                B Offline
                B Offline
                Brent Lamborn
                wrote on last edited by
                #7

                Found this on the web. It copies the selection in a drop-down to the clipboard. Could probably be modified to copy other text on the page: function copyText(theSel) { if (!document.all) return; // IE only theForm = theSel.form; theForm.copyArea.value=theSel.options[theSel.selectedIndex].value; r=theForm.copyArea.createTextRange(); r.select(); r.execCommand('copy'); }

                Please select A B

                "Half this game is ninety percent mental." - Yogi Berra

                1 Reply Last reply
                0
                • A Armando_Ramirez

                  I want to copy the whole page, My page doesnt have any pics, only text thanx ¡

                  E Offline
                  E Offline
                  enjoycrack
                  wrote on last edited by
                  #8

                  Just a suggestion, but IMO it's not the best ;P save the page's content into a hidden field before generating the page. Then, when user clicks on the button, just copy the value of the hidden field to the clipboard. Hope it gives u an idea... << >>

                  1 Reply Last reply
                  0
                  Reply
                  • Reply as topic
                  Log in to reply
                  • Oldest to Newest
                  • Newest to Oldest
                  • Most Votes


                  • Login

                  • Don't have an account? Register

                  • Login or register to search.
                  • First post
                    Last post
                  0
                  • Categories
                  • Recent
                  • Tags
                  • Popular
                  • World
                  • Users
                  • Groups