Discuss / JavaScript / linkCheck

linkCheck

Topic source

Junes_99994

#1 Created at ... [Delete] [Delete and Lock User]

$.fn.linkCheck = function() {

    return this.filter('a').filter(function() {

            const link = this;

            const origin = window.location.origin;

            const originCheck = link.href.include ? link.href.include(origin) : link.href.

indexOf(origin) !== -1;

            return !(originCheck || $(this).children('i.uk-icon-external-link').is

(":last-child"));

        }).attr('target', '_blank')

        .append('<i class="uk-icon-external-link"></i>')

        .click(function(e) {

            e.preventDefault();

            confirm('你确定要前往' + this.href + '?') ? window.open(this.href) : undefined;

        })

}

$('a').linkCheck();


  • 1

Reply