Forum Moderators: open
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.
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 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