Improve Your Rankings with a Sitemap That Works: The CSS - Sitemap Style Switcher
(Page 6 of 6 )
The JavaScript function that selects the correct stylesheet is extremely simple; it just detects whether the browser is MSIE, and re-writes the href attribute of the link element if it is:
function iestyle() {
if (document.body.createTextRange() != 'undefined') {
a = document.getElementById('link')
a.setAttribute('href','sitemapStyle.css');
}
}
As the createTextRange method is proprietary to Ineternet Explorer, it will not return undefined when IE is in use. When this condition is true, it selects the link element in the a variable and replaces the href attribute with the URL to the Microsoft-friendly CSS file using the setAttribute method. When a browser that doesn’t implement createTextRange (or any IE only object of your choice) runs the script, it will return undefined and the href attribute will not be changed in the HTML file, leaving the Mozilla friendly stylesheet in use.
The only down-side to this is that with JavaScript switched off in the browser, a visitor will default to the pretty plain looking un-styled list, so be sure to include <noscript> tags at the top of the page. Again, it’s more junk for the spiders to swallow, but it is good practice and should be adhered to, your visitors shouldn’t suffer at the hands of your SEO campaign.
Finally, just add an onload event handler to the <body> element of the main HTML page that calls the function then the page has loaded, and link the JavaScript file to the head of the HTML document. JavaScript should not be used in-line because it is something else that the search engine crawlers dislike and is more unnecessary data for them to ingest.
Test the page now in the mainstream browser of your choice and you should see the page as you intended to. There are still minute differences in the way the page is rendered in any of the different browsers but overall, it will look and feel the same.
An optimized sitemap should be part of any SEO campaign. Your entire site should be search-engine friendly and contain (at the very least) a sitemap already. You’ll find that search engine spiders may start to like your site a little more after they find your stash of links.
| DISCLAIMER: The content provided in this article is not warranted or guaranteed by Developer Shed, Inc. The content provided is intended for entertainment and/or educational purposes in order to introduce to the reader key ideas, concepts, and/or product reviews. As such it is incumbent upon the reader to employ real-world tactics for security and implementation of best practices. We are not liable for any negative consequences that may result from implementing any information covered in our articles or tutorials. If this is a hardware review, it is not recommended to open and/or modify your hardware. |