Howto Listen html link clicks and change them in STATIC HTML pages.....

  • Thread starter Thread starter Aykut Canturk
  • Start date Start date
A

Aykut Canturk

there's an aspnet site. some pages are html and cannot be changed. (no
javascript nor links can be changed).
these pages have links. for example a.html calls b. html like:

<a href="b.html"> page two link </a>

I need a listenet that can understand and say :

"hey somebody requested b.html." and will run some code, some db operations,
and according to result this istener will send b.html or instead of this it
will send another page...

any idea ?
 
Hi Aykut,
In the a.html you will need to capture the "OnClick" event of the anchor
tag....
Something like this <a id = "firstLink" href="b.html"
OnClike="ProcessClick()"> page two link </a>

Then you will need to write the Javascript function:

<script language="javascript">
function ProcessClick()
{
var ancTag = document.getElementById("firstLink");
//check for NULL condition
if(ancTag != null)
{
//Make your DB calls here
//Change the href as following
ancTag.href = "../SomeResult.html";
}
}
</script>

Hope this helps.

Let me know.

regards,
Joy
 
Hi Aykut,
In the a.html you will need to capture the "OnClick" event of the anchor
tag....
Something like this <a id = "firstLink" href="b.html"
OnClike="ProcessClick()"> page two link </a>

Then you will need to write the Javascript function:

<script language="javascript">
function ProcessClick()
{
var ancTag = document.getElementById("firstLink");
//check for NULL condition
if(ancTag != null)
{
//Make your DB calls here
//Change the href as following
ancTag.href = "../SomeResult.html";
}}

</script>

Hope this helps.

Let me know.

regards,
Joy

HI...

What joy suggested works fine... need modification to the html
Content

but there is another way to do that...

i have used only javascript to do such kind of things

here it goes....


add a function on page's onload ...

<body onload="load_content()"> like this..

and in my mark up i have,.....

<a id="mylink" href="Default.aspx">pagol naki</a>

now in load_content() method i have...

function load_content ()
{
var link = document.getElementById('mylink');
link.onclick = function()
{
window.alert('working');
//do your work...
//naviage it to some where else...
}
}

its works pretty fine and don't need to modify any thing on the
current html...

Best of luck

Munna
www.munna.shatkotha.com
www.munna.shatkotha.com/blog
www.shatkotha.com
 
Back
Top