A Link That Copies Text Then Redirects You

2 replies
  • WEB DESIGN
  • |
Hi Warriors,

I am a bit of a rookie when it comes to web design, especially more advanced techniques and I was wondering how I can set up a link that will copy text to a persons clipboard and then direct them to a site all in one click. Here is an example of what I mean...Check out www.retailmenot.com and look at their coupon codes. When you click the coupon code it copies it for you and takes you to the site. Anyone know a way to achieve this? Is there a WP plugin? or do I just need to insert some extra code?

Any help is much appreciated!
Sieger
#copies #link #redirects #text
  • Profile picture of the author CoursesWeb
    Hi
    It can be made with JavaScript. Here is an example, see the comments in code.
    Code:
    <span style="text-decoration:underline; cursor:pointer" onclick="copyRedir(this)">javascript</span>
    <script type="text/javascript"><!--
    // JS course - www.coursesweb.net/javascript
    function copyRedir(elm) {
      // Here set the link where to add the code and redirect
      var openpg = 'http://www.coursesweb.net/'
    
      // opens the address with the text from <span>...</span> added in URL
      window.open(openpg + elm.innerHTML);
    }
    --></script>
    {{ DiscussionBoard.errors[6041198].message }}
    • Profile picture of the author SiegerVinnare
      Thanks for the help! I'm having a bit of trouble getting it to work. What would I put where the "..." are between the span tags? I tried to just fill in the blanks and I got the correct link text but when I clicked it, it didn't do anything.

      Originally Posted by CoursesWeb View Post

      Hi
      It can be made with JavaScript. Here is an example, see the comments in code.
      Code:
      <span style="text-decoration:underline; cursor:pointer" onclick="copyRedir(this)">javascript</span>
      <script type="text/javascript"><!--
      // JS course - www.coursesweb.net/javascript
      function copyRedir(elm) {
        // Here set the link where to add the code and redirect
        var openpg = 'http://www.coursesweb.net/'
      
        // opens the address with the text from <span>...</span> added in URL
        window.open(openpg + elm.innerHTML);
      }
      --></script>
      {{ DiscussionBoard.errors[6041323].message }}

Trending Topics