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

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 ?
 
J

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
 
M

Munna

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,744
Messages
2,569,480
Members
44,900
Latest member
Nell636132

Latest Threads

Top