Reputation: 4492
I have a <a href="url1">url1</a>
.
But I have seen on websites that they would use javascript to show this as url1 but it is actually url1 which redirects to url2.
You would not see the original url when you hover your mouse over the link.
The same thing is also used on google's search results. Can you please suggest how it is done. :)
Upvotes: 0
Views: 2550
Reputation: 4704
You can use JavaScript onclick event to change the href on click.
Example: <a href="url1" onclick="this.href='url2'">link</a>
In this example users see that the link url is url1 but when they click on it goes to url2.
Upvotes: 2
Reputation: 21353
For a simple, example, you could make a redirect script that just takes the url out of a GET parameter, and then redirects the user to that page.
redirect.php:
<?php
$Link = $_GET['l'];
// Do whatever you want with $Link here (store it in a database, for example)
header('Location: ' . $Link);
?>
Now, instead of linking to url1, you can link to redirect.php?l=url1.
Please keep in mind that in an actual environment, you'd probably want to do some sanity checks on $Link before redirecting the user there.
Upvotes: 0