3

Is there a way to add a rel="nofollow" attribute to the window.open() Javascript function? Or is that any way to have Google not follow a link created by Javascript or jQuery.

Update

Also, this will be a product for a client and I will not have access to their files. Any changes the robot.txt or .htaccess are off the table.

GitaarLAB
  • 14,536
  • 11
  • 60
  • 80
Kyle
  • 227
  • 2
  • 12

3 Answers3

3

Google can read javascript links

In HTML5, the nofollow link type may only be used with a and area elements.

Since you are already using javascript.. (and can not access the robots.txt or .htaccess files), there is no reason why you couldn't use a normal (but hidden)
<a href="http://exampe.com" rel="nofollow" ...etc
(something that does support the attributes you seek, thus clearly and 'legally' indicating intention)
and use javascript to grab that URL (href attribute from the a element) to pass it to your window.open function.. However, I do not know if google wil honor this method.

Also (regarding your updated question), you can also set those directives using a meta header tag:
<meta name="robots" content="nofollow"> (and set endorsed links to rel="follow").


According to this excellent official google explanation (do give this a read or sit back and watch the talk..):

How does Google handle nofollowed links?

In general, we don't follow them. This means that Google does not transfer PageRank or anchor text across these links. Essentially, using nofollow causes us to drop the target links from our overall graph of the web. However, the target pages may still appear in our index if other sites link to them without using nofollow, or if the URLs are submitted to Google in a Sitemap. Also, it's important to note that other search engines may handle nofollow in slightly different ways.

According to wikipedia.org/wiki/Nofollow:

  • Google states that their engine takes "nofollow" literally and does not "follow" the link at all. However, experiments conducted by SEOs show conflicting results. These studies reveal that Google does follow the link, but it does not index the linked-to page, though it might be in Google's index for other reasons (such as other, non-nofollow links that point to the page).
  • Yahoo! follows it, but excludes it from their ranking calculation.
  • Bing also follows it, but excludes it from their ranking calculation.
  • Ask.com also respects the attribute.


PS: should anyone know (and be able to proof) that this wouldn't work.. leave a comment so future readers know that this workaround doesn't work as intended (and I'll amend my answer to reflect that).

GitaarLAB
  • 14,536
  • 11
  • 60
  • 80
  • Thanks for the long answer. I understand how the rel="nofollow" attribute works. My question is how can I get the same result when using `window.open('http://example.com', '_blank');` – Kyle Nov 06 '14 at 17:38
  • You are welcome (LOL, if 5 lines and 1 quote is considered 'long', I fear for the future of humanity `:)`). As I suggested in my answer: *use javascript to grab that `href`(url) from the hidden link to pass it to your window.open function..* (you were already using javascript): `window.open(hiddenLinkRef.href, '_blank');` – GitaarLAB Nov 06 '14 at 17:47
  • Wouldn't this still be no difference in Google's eyes? Google would still see that a redirect is happening from javascript and therefore Google will not treat as a advertisement. – Kyle Nov 06 '14 at 18:11
  • You wanted a way to 'legally' declare a `nofollow` on a URL (so crawlers that might respect valid markup instructions would pick this up). If you'd put the url 'directly' into the `window.open` you wouldn't have the possibility to specify that you'd want this to be `nofollow`.. Make sense this way? (Still, this would need to be tested. Also, *I think* google will 'silently' follow the links anyway.. not to mention other crawlers. But now it appears you want to HIDE a link from google (which isn't the same as telling google not to follow it)? – GitaarLAB Nov 06 '14 at 18:22
  • What I want to happen is that Google treats this link as a advertisement link. The only way I know how to do that in HTML is by adding a `rel="nofollow"` attribute to an `` tag. I want this exact same functionality using javascript. Since, I am only using javascript not adding an `` tag to the DOM, this seems to be impossible. – Kyle Nov 06 '14 at 18:25
  • One can use javascript to dynamically create an `a`-element. It is known that, since google executes and analyzes *basic* javascript, google will/should respect the `rel=nofollow` *dynamically added by javascript (on page-load)* to existing `a`-tags in HTML markup. One *might* obscure the url a *little*, let javascript create (not adding to layout) an `a`, set it to nofollow and add the `href`. Now google's script-engine should see a new link with nofollow set to it. Now you pass that link to your window opener. What I describe will work, question is: will it actually have the intended result? – GitaarLAB Nov 06 '14 at 19:03
  • Ok now I understand what you mean. I will have to test with Google to see if the outcome is what I want. Thanks for all the help :) – Kyle Nov 06 '14 at 19:13
  • ***Please* report back on that!!!** Since looking at all the separate parts of info, it *seems* that if we combine them, we get this 'solution'. (Note however, google (and other crawlers) continuously change the 'rules'). – GitaarLAB Nov 06 '14 at 19:16
2

Is there a way to add a rel="nofollow" attribute to the window.open() Javascript function?

No, but Google probably doesn't give any weighting to URLs opened with window.open in the first place.

Or is that any way to have Google not follow a link created by Javascript or jQuery.

nofollow, despite its name doesn't ask search engines not to follow a link, only to not treat the link as an endorsement for ranking purposes.

Use robots.txt if you want to ask search engines to stay away from URLs.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335
  • Thanks for the quick response. I have a script on my site that will redirect the user if they click on a certain DOM element. So to use your words I want Google and other search engines "to not treat the link as an endorsement for ranking purposes". – Kyle Nov 06 '14 at 16:43
0

You could put a disallow in your robots.txt

Shriike
  • 1,351
  • 9
  • 20