views:

235

answers:

2

One of my clients wants to distribute a javascript widget that people can put on their websites. However he wants to ensure that the backlink is left intact (for SEO purposes and part of the price of using the widget). So the javascript he's going to distribute might look like this:

<script id="my-script" src="http://example.com/widget-script.js"&gt;&lt;/script&gt;
<div style='font-size:10px'><a href='http://www.example.com/backlinkpage.html'&gt;
  Visit Exaxmple.com</a></div>

widget-script.js would display some html on the page. But what wew want to ensure is that some wiley webmaster doesn't strip out the back link. If they do we might display a message like "widget installed incorrectly" or something. Any ideas / thoughts.

Some code taken from this question.

A: 

If you wanted to ensure that the link is always there with the widget, you could just have it printed via JavaScript. However, I don't think search engines would pick it up as a backlink.

I think you're just going to have to trust that your users will act in good faith and show you the courtesy of not modifying/removing the link. You also need to accept that no matter what you do, a determined webmaster will be able to use your widget without displaying the link, and some inevitably won't, but they are likely to be in the minority (unless your backlink is just really intrusive or obnoxiously distracting).

Any JavaScript/HTML solution could simply be edited out by the webmaster. You'd have to make your widget in flash if you really want to prevent tampering.

Calvin
+3  A: 

There's no 100% way of preventing this, I'm afraid.

You could insert the link yourself with Javascript, but then it'd be for naught as far as PageRank goes. You could give them the HTML with the link having an ID like mycompanybacklink and check with Javascript whether the element exists or not. If it doesn't, don't display the badge or whatever. If it does, you can verify that the link's href is your website and its text is what you want. You would have to edit the HTML you posted as sample so that the link comes before the script, not after. The element could still exist, however, but be blocked by some other element or simply hidden with CSS. You could then also do something akin to what jQuery does now with its :hidden selector: Instead of looking at the CSS property by itself (which is what a webmaster is most likely to try) you can just see whether the element itself or its parents take up any space in the document. I think this is done with offsetWidth and offsetHeight but I am not sure. Worth looking into, though....

Paolo Bergantino
I'm not trying to prevent somebody with a lot of javascript knowledge to not be able to remove the link. Just something simple that most webmasters if they delete it will get a message and put it back in.
Keltex
Then just do the first technique. Check with the Javascript whether the link exists or not and whether the href of it is still pointing where you want.
Paolo Bergantino