1. This site uses cookies. By continuing to use this site, you are agreeing to our use of cookies. Learn More.

How to do this redirect.

Discussion in 'HTML & JavaScript' started by JJ228, May 13, 2014.

  1. JJ228

    JJ228 Newbie

    Joined:
    Apr 26, 2014
    Messages:
    14
    Likes Received:
    0
    Hello,

    I have a button on my site, I want user to be redirect after x seconds once the button is clicked.

    Can anyone please share the code.

    Thanks
     
  2. tg01

    tg01 Regular Member

    Joined:
    Aug 23, 2007
    Messages:
    451
    Likes Received:
    129
    Gender:
    Male
    This could easily be achieved in jquery:-
    <script>
    $("#buttonid").click(function() {
    $(location).attr('href', 'website address / url to redirect to').delay("time in milliseconds");
    });
    </script>
    To use the above add the id "buttonid" to the item you wish people to click, change the website address / url and adjust the time in milliseconds.

    I have not run the code, though jquery is pretty simple.

    Hope it helps.
     
  3. JJ228

    JJ228 Newbie

    Joined:
    Apr 26, 2014
    Messages:
    14
    Likes Received:
    0
    Thanks, I don't know much coding, just simple html.

    This is my button code - <div class="fb-share-button" data-href="http//MYDOMAINdotcom" data-type="button"></div>

    Can you implement the code with my button for me.

    Thanks alot.
     
  4. Tanckom

    Tanckom Power Member

    Joined:
    May 4, 2014
    Messages:
    571
    Likes Received:
    174
    Location:
    ☯ Karma ☯
    Home Page:
    on the internet you will find some generators who will do that
     
  5. JJ228

    JJ228 Newbie

    Joined:
    Apr 26, 2014
    Messages:
    14
    Likes Received:
    0
    Can you tell what to search.
     
  6. IMCapitalist

    IMCapitalist Senior Member

    Joined:
    Jan 21, 2014
    Messages:
    1,090
    Likes Received:
    60
    Location:
    Google Universe
    I can do it for you dude.
     
  7. tg01

    tg01 Regular Member

    Joined:
    Aug 23, 2007
    Messages:
    451
    Likes Received:
    129
    Gender:
    Male
    Simply change the jquery, where I have used "#buttonid" change this for ".fb-share-button", would you like the page to redirect to a different href for each link?

    If so the code would be:

    Code:
    <script>
    $(".fb-share-button").click(function() {
       var redirectUrl = $(this).attr("data-href");
       $(location).attr('href', redirectUrl).delay("time in milliseconds");
    });
    </script>
    
    To get the above working simply adjust the delay length and copy / paste into your html head.

    PM me with any questions.
     
    • Thanks Thanks x 1
    Last edited: May 13, 2014
  8. mozgoweb

    mozgoweb Newbie

    Joined:
    May 18, 2014
    Messages:
    16
    Likes Received:
    2
    Solution with no jQuery:

    Code:
    <div class="fb-share-button" data-type="button" onclick="javascript: setTimeout(function(){location.href='http//MYDOMAINdotcom'}, 3000);">
    </div>