External Link Notification - JavaScript or JQuery

前端 未结 4 1421
隐瞒了意图╮
隐瞒了意图╮ 2021-01-26 00:31

I am looking for a way to set it up so that when an external link is clicked it will warn people that they are leaving the site. Preferably, it would darken the screen and displ

4条回答
  •  死守一世寂寞
    2021-01-26 00:56

    It worked pretty well to me. I just removed unnecesary variables, but original script worked fine.

    $('a').filter(function() {
        return this.hostname && this.hostname !== location.hostname;
    })
    .click(function () {
        return window.confirm('You are about to proceed to an external website.  The Great Western Market has no control over the content of this site.  Click OK to proceed.');
    });
    

    http://jsfiddle.net/3dkAN/1/

    EDIT

    Following @user1308743's line, seems that in cgmp.framework.min.js is summoning the jQuery.noConflict() mode, that unbinds the $() function for jQuery. So please use jQuery() for any jQuery implementation

提交回复
热议问题