Forum Moderators: open

Message Too Old, No Replies

Will google read Javascript link?

Alternative to target="_top"

         

twist

5:14 am on Jan 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



While trying to validate my code I inevitably came across the target issue. Many website developers in my area are framing popular local websites into their sites. I was hoping to avoid the issue by adding target="_top" to my main menu which is repeated on every page. This way if they frame me my site will break it. I am using this line of code below but am concerned that google may not pick up the links.

<a href="#" onclick="window.top.location.href=\'http://site.com/page.htm\'">link</a>

I don't really like this method but after all my other work to clean up my code I would hate to lose validation. Any one have any ideas?

BlobFisk

11:55 am on Jan 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



You're right twist, Google does not read javascript links. You can add a workaround to you existing line as follows:


<a href="page.html" onclick="window.top.location.href=\'http://site.com/page.htm\'; return false;">link</a>

Google will follow the link in the href, but browsers will use the javascript command and ignore the href. They do this because of the return false. This tells the browser to ignore the default behaviour (following the href) and execute the onClick behaviour instead.

HTH.

Brett_Tabke

2:09 pm on Jan 12, 2004 (gmt 0)

WebmasterWorld Administrator 10+ Year Member Top Contributors Of The Month



google will read ANY HTTP that looks like a url on a page - even if it is in Javascript. Just use full absolute urls and don't break the lines and Gbot will read your js links just fine.

BlobFisk

2:25 pm on Jan 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



I stand corrected - thanks for that Brett. Every day is a school day!

twist

6:12 pm on Jan 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Thanks guys, you were both very helpful. Just learned 2 new things.

choster

6:16 pm on Jan 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



To force every page to break out of frames upon loading (when Javascript is not disabled), we use

<script type="text/javascript">
if (window!= window.top)
top.location.href = location.href;
</script>

twist

6:52 pm on Jan 12, 2004 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



choster, you just saved me a butt-load of time. Man this site is great.