I would like to interrupt navigation events in a web page using javascript (jQuery ideally) to verify that the link works before the navigation happens.
Background: this is for verify links in Visio diagrams printed to web pages.. so the navigation instruction will be coming from JavaScript not an HTML el开发者_如何转开发ement AFAIK. I am trying to avoid having to learn how the Visio generated page to achieve this, so I am hoping it can be done in a generic way by interrupting the navigation, and trying to load the page before continuing.
with jQuery live if you need to add links dynamically too:
$("a").live("click", function () {
return testUrl($(this).attr('href'));
});
function testUrl() {
// return false if not valid;
// else return true;
}
Returning false will stop the event's default behavior.
精彩评论