How can I detect rel="noreferrer" support?
Asked Answered
H

2

9

Is there any way I can detect the support for rel="noreferrer" with Javascript?

<a href="http://example.com" rel="noreferrer">link without referral</a>

Solution - $.browser is deprecated, and it may be moved to a plugin in a future release of jQuery.

var is_webkit = $.browser.webkit;
if(is_webkit) {
    alert('supports rel="noreferrer"');
}
Harlin answered 3/12, 2011 at 19:30 Comment(1)
@DavidThomas you might want to check the solution i posted above.Harlin
W
0

No, there is none. Referrer headers are outside the domain of JavaScript.

If it's particularly important, you could check whether the browser (navigator.userAgent) is one known to support or not support noreferrer.

Whirl answered 3/12, 2011 at 19:35 Comment(2)
i know this is deprecated, but still works for my purpose: var is_webkit = $.browser.webkit;Harlin
This is wrong. I detect noreferrer support in hotlink.js (github.com/eligrey/hotlink.js/blob/master/hotlink.js) with iframes.Prompter
P
17

I detect noreferrer support by creating a hidden iframe with a name attribute, and then I create an <a rel="noreferrer"> link with its target attribute equal to the iframe's name attribute, and have the link point to any resource on the current domain. Linking to about:blank also works, but it has problems in Firefox and IE, so you should instead link to an intentionally blank file on your server. After the resource is loaded in the iframe, check that [the iframe].contentDocument.referrer === "". If this is true, noreferrer is supported.

An example of my implementation is available in hotlink.js. Specifically, see on_ready.

Prompter answered 5/4, 2012 at 0:5 Comment(0)
W
0

No, there is none. Referrer headers are outside the domain of JavaScript.

If it's particularly important, you could check whether the browser (navigator.userAgent) is one known to support or not support noreferrer.

Whirl answered 3/12, 2011 at 19:35 Comment(2)
i know this is deprecated, but still works for my purpose: var is_webkit = $.browser.webkit;Harlin
This is wrong. I detect noreferrer support in hotlink.js (github.com/eligrey/hotlink.js/blob/master/hotlink.js) with iframes.Prompter

© 2022 - 2024 — McMap. All rights reserved.