Previously, In the post
Why People Hate Javascript, I spotlight an example where Firefox does one thing and Internet Explorer — I'll step out and say that Firefox does the right thing and IE does the wrong thing, but if there's doubt about which is correct in the language specification, that's a bad on the standards committee — and I was rightly, correctly informed that
Javascript, through the DOM, had a means to get the information I needed without relying on the hated
x.split()
. Which I include below the cut.
$(function() {
var protocol = window.location.protocol ;
var hostname = window.location.hostname ;
var path = window.location.pathname ;
var query = window.location.search ;
var hash = window.location.hash ;
var url = protocol + '//' + host + path + query + hash ;
if ( host != hostname ) {
window.location.replace( url ) ;
}
} ) ;
The hostname you want to redirect to is placed at your discretion as var host
, but I choose not to include it here. The only jQuery aspect to this is the wrapper, which makes this script run when the page is fully loaded. Which probably isn't strictly necessary. And this does work on both IE and FF.
No comments:
Post a Comment