diff --git a/README.md b/README.md index 63027ff..a39c8e5 100644 --- a/README.md +++ b/README.md @@ -56,6 +56,24 @@ var linkInfo = {rel: "icon", type: "image/png", href: "/icon.png"}; DocHead.addLink(linkInfo); ~~~ +#### DocHead.hasLink(metaInfo) + +Check if a Link tag with a matching `.href` attribute exists in the head. + +~~~js +var linkInfo = {rel: "icon", type: "image/png", href: "/icon.png"}; +DocHead.hasLink(linkInfo); +~~~ + +#### DocHead.removeLink(metaInfo) + +Removes all link tags with a matching `.href` attribute. + +~~~js +var linkInfo = {rel: "icon", type: "image/png", href: "/icon.png"}; +DocHead.removeLink(linkInfo); +~~~ + #### DocHead.addLdJsonScript(jsonObj) Add a Script tag with type of `application/ld+json`. diff --git a/lib/both.js b/lib/both.js index f544bab..946cfd0 100644 --- a/lib/both.js +++ b/lib/both.js @@ -25,6 +25,16 @@ DocHead = { addLink(info) { this._addTag(info, 'link'); }, + hasLink(info) { + if (Meteor.isClient) { + return this._hasTag(info, 'link'); + } + }, + removeLink(info) { + if (Meteor.isClient) { + this._removeTag(info, 'link'); + } + }, getTitle() { if (Meteor.isClient) { titleDependency.depend(); @@ -49,6 +59,26 @@ DocHead = { this._addToHead(meta); } }, + _hasTag(info, tag) { + return !!this._findTagByHref(info.href, tag); + }, + _removeTag(info, tag) { + const elements = document.querySelectorAll(tag); + for (let element of elements) { + if (element.getAttribute('href') === info.href) { + element.parentNode.removeChild(element); + } + } + }, + _findTagByHref(href, tag) { + const elements = document.querySelectorAll(tag); + for (let element of elements) { + if (element.getAttribute('href') === href) { + return element; + } + } + return null + }, _addToHead(html) { // only work there is kadira:flow-router-ssr if (!FlowRouter) {