Reputation: 726
Everyone!
Almost 3 hours im stack in this problem! iv'e copy the concept in twitter like this if twitter.com/#!/username then the page/profile is username,
http://twitter.com/#!/mardagz as you can see it redirected to my account, so now im trying to make my own by getting the current url.. then i trim to string and split it by (/#!/) and when i try to apply nothing works...
assuming that the current url is http://www.domain.com/#!/about
the Code:
$(window).load(function () {
var getUrl = top.location;
var trimUrl = jQuery.trim(getUrl);
var splitUrl = trimUrl.split('/#!/')
//alert(splitUrl[1]);
switch(splitUrl[1])
{
case 'home':
//Do Something
break;
case 'skill':
//Do Something
break;
case 'about':
//Do Something go to About Us Page!
break;
}
});
owhh it's not working... whew anyone has a solution for this? :) thank you in advance.. :)
Upvotes: 4
Views: 122
Reputation: 348972
If you want to detect a hash change, use the hashchange
event. The code below will work like a charm if your top-level window is at the same domain. Otherwise, the Same origin policy will prevent your script from accessing the location
object of the top document.
function hashChanged() {
var getUrl = top.location.hash.substr(3); // #!/ = 3 characters
switch(getUrl)
{
case 'home':
//Do Something
break;
case 'skill':
//Do Something
break;
case 'about':
//Do Something go to About Us Page!
break;
}
}
$(window).load(function(){
// Set handler
$(window).bind('hashchange', hashChanged);
// Handle hash on load
hashChanged();
});
Upvotes: 6