Rosetta Code:Village Pump/Language Page Links: Difference between revisions

Content added Content deleted
No edit summary
No edit summary
Line 33: Line 33:
category = document.referrer.match(/\/Category:([^\/]+)$/)[1];
category = document.referrer.match(/\/Category:([^\/]+)$/)[1];
if(category == null) return;
if(category == null) return;
if(!document.body.innerHTML.indexOf("\"/wiki/" + category + "\"") return; //EDIT: just added this line to try to fix ALL redirects. Now it isn't tested, but it should still work.
if(!document.body.innerHTML.indexOf("\"/wiki/" + category + "\"")) return; //EDIT: just added this line to try to prevent it from redirecting pages that aren't in the category (and thus don't have a solution or anchor) to the categories section. Now it isn't tested, but it should still work.
window.location.hash = category;
window.location.hash = category;
}</lang> Tested with IE, FireFox, Opera, Chrome, Safari (from multiple categories to multiple problems, including "dud" categories without the code, and from non-categories). Should work with others too, nothing special was done. In IE theres a little bug - go to category, click link, it'll take you to the right section. Press the Back button and it'll take you to the top of the page, hit Back again to get back to the category. In all of them, links from any page that starts with "Category:" to any page with the problem template will attempt to redirect to #category-name (I think it's fixed now).
}</lang> Tested with IE, FireFox, Opera, Chrome, Safari (from multiple categories to multiple problems, including "dud" categories without the code, and from non-categories). Should work with others too, nothing special was done. In IE theres a little bug - go to category, click link, it'll take you to the right section. Press the Back button and it'll take you to the top of the page, hit Back again to get back to the category. In all of them, links from any page that starts with "Category:" to any page with the problem template will attempt to redirect to #category-name (I think it's fixed now).