We launched new forums in March 2019—join us there. In a hurry for help with your website? Get Help Now!
    • 28033
    • 925 Posts
    You know how some websites have that "click to copy this address"?

    1) How could I grab the URL using MODx? Does MODx have a variable that does this?
    2) How could I make it so when the user clicks the text, it auto-copies, instead of them having to copy it?
      My Snippets
      -> PopUpChunk v1.0
      • 3749
      • 24,544 Posts
      This should give you the full URL:

      [~[+id+]~]



      So this (in theory, I haven’t tried it) should copy the link to the user’s clipboard. Not sure if it will work in all browsers (should work in IE). Someone else may know a more generic solution.

      <span id="copytext" style="height:150;width:162;background-color:pink">
      [~[+id+]~]
      </span> 
      <textarea id="holdtext" style="display:none;">
      </textarea>
      <button onClick="ClipBoard();">Copy to Clipboard</button> 

      <script language="JavaScript">
      
      function ClipBoard() 
      {
      holdtext.innerText = copytext.innerText;
      Copied = holdtext.createTextRange();
      Copied.execCommand("Copy");
      }
      
      </script> 


      grin
        Did I help you? Buy me a beer
        Get my Book: MODX:The Official Guide
        MODX info for everyone: http://bobsguides.com/modx.html
        My MODX Extras
        Bob's Guides is now hosted at A2 MODX Hosting
        • 33337
        • 3,975 Posts
        It should be [~[*id*]~] ... notice the asterisk. wink

        And to get full url, you need to prefix: [(site_url)]. But if you have <base href="[(site_url)]" /> in the <head> section then you don’t need it.

        regards.
          Zaigham R - MODX Professional | Skype | Email | Twitter

          Digging the interwebs for #MODX gems and bringing it to you. modx.link
          • 28033
          • 925 Posts
          EDIT: BTW, that solution doesn’t work outside IE.

          I did find a universal solution. Still requires a click on a button to work, although I’m trying to see if I can automate it when they click on the form...
            My Snippets
            -> PopUpChunk v1.0
            • 7231
            • 4,205 Posts
            Still requires a click on a button to work
            I think that if you change the onClick to onFocus or onBlur the javascript will work without a click.
              [font=Verdana]Shane Sponagle | [wiki] Snippet Call Anatomy | MODx Developer Blog | [nettuts] Working With a Content Management Framework: MODx

              Something is happening here, but you don&#39;t know what it is.
              Do you, Mr. Jones? - [bob dylan]
              • 3749
              • 24,544 Posts
              Quote from: zi at May 30, 2008, 06:19 AM

              It should be [~[*id*]~] ... notice the asterisk. wink

              And to get full url, you need to prefix: [(site_url)]. But if you have <base href="[(site_url)]" /> in the <head> section then you don’t need it.

              regards.

              Oops. Copied that from either the Ditto or Wayfinder docs. If I understand this correctly, my version would work if you’re using either Ditto or Wayfinder because they set up the [+id+] placeholder. Your solution is more generic and therefore much better.

              Bob
                Did I help you? Buy me a beer
                Get my Book: MODX:The Official Guide
                MODX info for everyone: http://bobsguides.com/modx.html
                My MODX Extras
                Bob's Guides is now hosted at A2 MODX Hosting