Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Webcrawler thinks this JavaScript call is an error

Status
Not open for further replies.

AndyGroom

Programmer
May 23, 2001
972
GB
I've used Google Webmaster tools to get a report on my website and virtually every page throws up an error due to a particular line of code, here's a typical example:
Code:
var site = '[URL unfurl="true"]http://www.mysite.com/showthread.php?t=#';[/URL]
...
<a href='javascript:open(85999);'>Open Link</a>
The Webcrawler tries to access a page on my site called 85999 and gets a 404 error. However the Javascript code actually opens a new window taking the user to a new website inserting the number passed to "open" in the relevant place, eg:
Code:
function open(thread)
{
  window.location = site.replace("#", thread);
}
Is there a way I can alter the <a href> link so that the webcrawler doesn't try to access it as a page on my site?

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
how does the javascript provide value? if you want to open a new window/tab, set the target.
Code:
<a href='[URL unfurl="true"]http://www.mysite.com/showthread.php?t=85999'[/URL] target="_blank">Open Link</a>


Jason Meckley
Programmer

faq855-7190
faq732-7259
 
The function open() is held in a separate .js file along with other routines, so that if at some point in the future I wanted to open a link in a different way I could change the code and wouldn't have to upload all the pages again. The Site variable is set on each page.

- Andy
___________________________________________________________________
If you think nobody cares you're alive, try missing a couple of mortgage payments
 
you are using javascript to control how the html works instead of allowing the javascript to enhance how it works. the webcrawler only sees the html, it doesn't care what the user experience is like.

if you want to enhance the links you can do that using javascript is an unobtrusive way. here is one example using jquery.
Code:
$(function(){
   $('a').click(function(){
      window.location = this.href;
   });
});
...
<a class="make-me-pretty" href="...">text</a>
if you need to be selective about which links to change you could do that any number of ways. using a class for example
Code:
$(function(){
   $('a.overridenavigation').click(function(){
      window.location = this.href;
   });
});
...
<a class="make-me-pretty overridenavigation" href="...">text</a>
this way the html is correct and still works whether javascript is enabled or not.

Jason Meckley
Programmer

faq855-7190
faq732-7259
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top