1

i am havige huge static site with lots lots of links. For example on one page i have like 80 inner links. I want to hide it from Google. I seen some people did it thru click() in jQuery. For example

 <script>
 $(".linkname").click(function(){
     document.location.href = 'inner.html';
 });
 </script>

And i add class to for example span element .linkname and its linked to proper page and for google its not a linl. So all good. But what happens when i have 100 links on page. That means i must assign each link different class and make new code to link to proper page. Since all links leads to different pages. How can i speed up this proces make it dynamic? I dont want to make 100 new classes and 100 new functions to recognize that link and link it to correct page.

Any help ideas?

1
  • I think you have to try with robots.txt or else something like that..!! Commented May 23, 2013 at 10:42

3 Answers 3

3

One class is enough:

<span class="linkname" data-url="http://mywebsite.com">website1</span>
<span class="linkname" data-url="http://mywebsite2.com">website2</span>

$(".linkname").click(function(){
     document.location.href = $(this).data('url');
 });
Sign up to request clarification or add additional context in comments.

Comments

0

give the link name same as page name.Then try this

<script>
 $(".pageName").click(function(){
     var name = $(this).attr('class');
     document.location.href = '"+name +".html';
 });
 </script>

Comments

0

You could assign the url to an attribute of the span, for example you can use the "rel" attribute, and catch it in the click event.

So, your span will be:

<span class="link" rel="http://www.google.it">this is a fake link</span>

and your code will be

$(".link").click(function(){ document.location.href = $(this).attr('rel'); });

i suggest you to switch to the new 'on' method (http://api.jquery.com/on/). the code will be something like:

$(".link").on('click', function(){ document.location.href = $(this).attr('rel'); });

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.