Test if links are external with jQuery / javascript?

后端 未结 13 1335
囚心锁ツ
囚心锁ツ 2020-11-28 05:00

How do I test to see if links are external or internal? Please note:

  1. I cannot hard code the local domain.
  2. I cannot test for \"http\". I could just as
13条回答
  •  时光取名叫无心
    2020-11-28 05:48

    var external = RegExp('^((f|ht)tps?:)?//(?!' + location.host + ')');
    

    Usage:

    external.test('some url'); // => true or false
    

提交回复
热议问题