Bookmarklet: Redirecting to m.*.* for Mobile Browsers & www.*.* for Desktop Browsers
Is there a JavaScript hack I could place in the URL field which would guide mobile browsers to "m."
prefixes and guide my desktop to "www."
prefixes, if I provide the "<domain>.<r开发者_JS百科oot>"
suffix?
I think this would be useful for both Weave and Opera Link users.
Your problem is that window.location.href
is a property, not a method.
You're trying to set the browser location by code along the lines of:
window.location.href("http://www." + address)
What you should be using instead is
window.location.href = "http://www." + address;
If you change your bookmarklet accordingly, it seems to function correctly (i.e. it takes me to www.cnn.com when I paste it into my address bar). I thought about posting the corrected code here but on reflection I think that would be patronising.
A Working Script:
javascript:(function(){url="digg.com";if(screen.width<=480&&screen.height<=320){window.location.href="http://m."+url}else{window.location.href="http://www."+url}})()
精彩评论