开发者

is it possible to interupt navigation events to test link target with javascript?

开发者 https://www.devze.com 2023-03-29 12:46 出处:网络
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.

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.

0

精彩评论

暂无评论...
验证码 换一张
取 消