Skip to content

Instantly share code, notes, and snippets.

View nguyenning's full-sized avatar
💥
Super

Alex Nguyen nguyenning

💥
Super
  • Wood PLC
  • Houston, TX
View GitHub Profile
@nguyenning
nguyenning / isexternalurl.js
Last active August 29, 2015 14:04
Checks if url is an external url or not.
var isExternalUrl = function (url) {
/* Tests if valid absolute url, ex:
* http://www.google.com | https://www.google.com | //www.google.com
*/
if (new RegExp('^((https?:)?//)', 'i').test(url)) {
var target = document.createElement('a');
target.href = url;
// note: hostname will be empty in IE for local urls
if (target.hostname.length > 0 &&