I have a link that has an href of "/news#1930"
. When I click on this link when on the /news
page, it does not refresh the page (it just adds #1930 to the end of the URL). I would like it to refresh the page though (I am using the info after the # tag with some jquery to load that specific article in a corresponding iframe and when it doesn't refresh it won't load the new article). Any ideas on how to force the refresh?
The code I have currently is:
$(document).ready(function() {
var $news_story = $(window.location.hash.substring(1)),
$news_number = $news_story.selector,
$news_url = 'http://www.synergy-pr.com/news/mediacenter/index.html?view=article&CustomerID=41b1if9-a17d4va5sf7of15e3kb0pa3kd2y-99d03n8sq4ad2xk8h47j00r98el5pf&ClientArticleID=' + $news_number, //url of specific article
$news_url_default = 'http://www.synergy-pr.com/news/mediacenter/index.html?CustomerID=41b1if9-a1hd4xa52f78f1ke3bb0oa3ld2k-90208c8g64x02nh8wf7ad0m181p5su'; //url of general news page
if ($news_number.length>0) { //if their is a # with a number, this means it is a sidebar link and should load that specific article
$('#news-feed').attr('src', $news_url);
} else { //if not, load the main news page
$('#news-feed').attr('src', $news_url_default);
}
});
This code will reload every page witch link has hash
Try this:
Try a space before the hash:
Hashes are meant to not cause a page reload. If you're using jQuery to load that article you may want to perform a history.go(0) or window.location.reload, then use jQuery to find the hash tag and process (on the load event of the refreshed page).
EDIT I assume you're going the hash route for the same reason websites like facebook do as well--for book-mark ability and indexing despite that you're using ajax for the seamless integration.
EDIT 2 Here is what I've come up with to show what I'm referring to. This will load up a hash that's been passed through the URL and handle any new clicks to new articles within the page.