Forum Moderators: open

Message Too Old, No Replies

Can I intercept a link off my page?

         

the_kraken

1:18 pm on Jul 31, 2006 (gmt 0)

10+ Year Member



OK, before anyone gets fired up, I am not trying any nefarious activity on my users. I have an intranet app that connects to Documentum for content. Our org. is switching to a Domino based content manager and I want to be able to pick up any links on the intranet that are going to the old server, and send them to the new one. Most of our intranet content is managed by the businesses, not the IT org, and the old server has to stay live for a testing period, so I can't implement a Virtual Server in IIS (yet).

Is there anything I can utilize to pick up this click? I will know the beginning of the URL they are clicking, it won't change. Is there software that will do this, or a script of some type?

Thanks for any help.

Fotiman

4:13 pm on Jul 31, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



If all of the pages use a shared "layout" file that you could modify, then you could probably do this with javascript.

Get all of the "a" nodes and attach an onclick event handler. This handler would look at the current URL of the link. If it contained the old server, then redirect to the new server. You might look into using the Yahoo UI Library for attaching the onclick event handler (very easy to use).
[developer.yahoo.com...]

Wish I had more time to be more specify, but you'd probably want to do something like this:



<!-- Namespace source file -->
<script type="text/javascript" src="yahoo.js" ></script>
<!-- Event source file -->
<script type="text/javascript" src="event.js" ></script>
<script type="text/javascript">
function attachEventHandlers()
{
var aNodes = document.getElementsByTagName("a");
for( var i = 0; i < aNodes.length; i++ )
{
// Attach event handler to link
YAHOO.util.Event.addListener(aNodes.item(i), "click", redirectTest);
}
}
function redirectTest(e)
{
alert("click");
// Check the href
// redirect if needed
}
// Attach method to the document onload event
YAHOO.util.Event.addListener(window, "load", attachEventHandlers);
</script>

I you may need to use the addListener method that takes additional arguments in order to pass the "a" node to the handler... not sure. Anyway, hope that helps.

the_kraken

3:02 pm on Aug 3, 2006 (gmt 0)

10+ Year Member



ok, I have this working in theory, now another problem arises:

The page I am trying to pick the link up from is in a frame, and the source is generated dynamically and I don't have control over the source document. Meaning that I can't automatically put this script in each of the pages that gets loaded into the frame.

I tried to load it from the main frame of the page using:
YAHOO.util.Event.addListener(window.parent.frames[1], "load", attachEventHandlers);

but to no avail. Anyone have any other ideas or suggestions? Thanks