javascripthtmlhttp-redirectuser-profile

Redirect visitor to his/her SO profile from my profile


I want to add a link in my profile which will redirect the visitor to his/her profile when it will be clicked.

I came across a profile few week ago(tried to find account but no luck ) which has the same implementation like as written below

i always upvote (this user) ... etc where this user is a hyperlink which redirected me to my profile (seems cool to me).

Attempts Info

As we know , we can use html so it was easy to put a static link there like

<a href="http://stackoverflow.com/users"> Testing</a>

but the implementation required the dynamic code which should appends the user id at the end of the link so i thought of Javascript but it can't be used directly , result in the same JS code to displayed on my profile along with script tags.

but then i wrote the whole HTML template as and no script tag shown in my profile

<!DOCTYPE HTML>
<html>
<head>
  <script>
      window.localStorage.getItem('username'); // appear as it is
  </script>
</head>
<body>
<a href="http://stackoverflow.com/users"> Testing</a>
</body>
</html>

but still , whatever i write inside script , displayed as it is on my profile screen, even i thought to get the username from cookies or browser but no luck

1.) How can get the visitor profile link and use it as href link ?

right now it looks like this and clicking on testing link, redirect visitor to users tab on SO site which is not desirable

enter image description here

i would really appreciate any help or direction . Thanks you

Note : you can try this in your profile too , just copy paste the code in your profile section , i am not really asking to visit my profile for views


Solution

  • I been trying since from two days and finally i just managed to do this by just making a small amendment to my code , no javascript required. Hurrraah!

    All i needed to do was, add /current at the end of my URL's href link which will take the visitor to his/her profile when clicked.

    so it should be like this

    <a href="http://stackoverflow.com/users/current">
    

    instead of this

    <a href="http://stackoverflow.com/users">
    

    small things do help !