Forum Moderators: open

Message Too Old, No Replies

Track how a user opens a link

         

jsphtml

1:36 am on Dec 23, 2004 (gmt 0)

10+ Year Member



Hey I am a new member here....

I have question regarding the above subject.

Basically, if a user if presented with a simple
<a href=""></a> based link, the user can either click on it to open it or right click on the link and open that in a new window.

My question is how can I stop the user from right clicking on the link and opening it (I know I can disable right clicks...but that will be my last resort).

If I cannot stop it, is there a way for me to track that the user opened a link using right click and then display, a warning msg on the new window...?

I have seen the above warning behaviour on an online banking website which was HTTPS enabled...not sure if we need HTTPS for this behaviour or can JS work here. Tried to look at their JS code but the whole thing seems to be hidden...:(

Thanks for any inputs....!

Bhushan.

jsphtml

2:50 pm on Dec 23, 2004 (gmt 0)

10+ Year Member



BTW, The application that I am working on is intranet based so, there is no cross browser programming/complication.

Our target browser is (guess what!) Internet Explorer 5+.

I guess this will ease a few things..!

thnx.

flashfan

1:36 am on Dec 24, 2004 (gmt 0)

10+ Year Member



You may use <a href='yourcgi?url=realurl'>click here</a>, and 'yourcgi' will do the track work.

Lance

11:46 am on Dec 24, 2004 (gmt 0)

10+ Year Member



How would 'yourcgi' know which mouse button was pressed?

flashfan

3:19 pm on Dec 24, 2004 (gmt 0)

10+ Year Member



How about overwrite right click?

Lance

4:45 pm on Dec 24, 2004 (gmt 0)

10+ Year Member



There's probably a much more elegant way to do this, but this would intercept the right-click only on the <a> elements and cause it to just follow the link as if it had been clicked.


<script type="text/javascript">
window.onload = Init;

function Init() {
if (!document.getElementsByTagName) return;
var anchors = document.getElementsByTagName("a");
for (var i=0; i<anchors.length; i++) {
var anchor = anchors[i];
anchor.attachEvent("oncontextmenu", FollowLink);
}
}

function FollowLink() {
document.location.href = event.srcElement.href;
return false;
}
</script>

<p><a href="http://www.google.com/">Google</a></p>
<p><a href="http://www.yahoo.com/">Yahoo</a></p>

jsphtml

7:38 pm on Dec 24, 2004 (gmt 0)

10+ Year Member



Hey Lance,

Thnx for the response....this looks like a good process. I am gonna try it out right now...!

Let me explain what our problem is:-
We are using session based objects which are shared when the user moves from one IE window to the other in the same "IE instance"...but if the user opens a new IE window from the existing IE window/instance, the session now gets shared between two "separate" windows(which spawned from the same instance) that corrupts session data....

So another issue we have is: Is there a way for us to trap the event when the user opens a new window through menu:
File --> New --> Window....?

Currently I have been able to trap the (cntrl + N) route, and display a warning message but still trying to figure out way to trap file new window route. above...

Thnx for all ur help...!