How to make Dynamic URL in HTML by using Events

Its quiet easy to make dynamic URLs if you are using Javascript or PHP. But if you want to use pure HTML then what will u do ? In this post i will tell you a very simple code in HTML to create a dynamic URL.


What is Dynamic URL ?

A dynamic URL is an address which is generated by a web page when it is needed. It can also be called Dynamic Hyperlinks. To understand it better lets take a look at Static URL( or Static Hyperlinks).

HTML Code
<a href="http://www.facebook.com/sharer.php?u=http://bestrix.blogspot.com" target="_blank" rel="nofollow">Share on Facebook</a>


Output:
Share on Facebook


This Hyperlink contain a Static URL which will always remain same, no matter which post you are reading. It will share the homepage of my website i.e http://bestrix.blogspot.com on facebook. But here need some dynamic URL which can change itself to current post's address, so that it can be shared by users.

How to create Dynamic URL ?

Now i will write a code that will generate Dynamic Hyperlink, as the URL will change itself to current post's address.

HTML Code
<a href="http://www.facebook.com/sharer.php?u=http://bestrix.blogspot.com" target="_blank" rel="nofollow" onmouseover="this.href='http://www.facebook.com/sharer.php?u='+encodeURIComponent(location.href);">Share on Facebook</a>


Output:
Share on Facebook


As you can see that the above hyperlink points to share the current post's URL.
So you can use "onmouseover" event to change the dynamic hyperlinks on your webpage.

This event is very simple.
onmouseover="this.href = 'urlHere';"
you can put it inside <a> tag to generate dynamic hyperlinks.
Share this Article :
Email

No comments:

Post a Comment