Created
October 28, 2016 21:05
-
-
Save lowmess/f46b6429a65ddcece42ae2fbc9ef4828 to your computer and use it in GitHub Desktop.
functions for manipulating external-facing links
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export function queryString (el, string) { | |
// Check if el is a link | |
if (!el.href || (el.protocol !== 'http:' && el.protocol !== 'https:')) return | |
// Check if link host does not match current window host | |
if (el.host !== window.location.host) { | |
// If link already has a query string add to it, else create one | |
if (el.search) { | |
el.search += '&' + string | |
} else { | |
el.search = string | |
} | |
} | |
} | |
export function linkTarget (el, target) { | |
// Check if el is a link | |
if (!el.href || (el.protocol !== 'http:' && el.protocol !== 'https:')) return | |
// Check if link host does not match current window host | |
if (el.host !== window.location.host) { | |
// If link doesn't already have a target, set one | |
if (!el.target) el.target = target | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment