我有一个带有 iframe 和侧边栏链接的页面。侧边栏链接指向 iframe 中加载的文章。每个侧边栏链接都有一个类似“/news#1940”的链接,其中#标签后面的数字对应于文章的ID。然后,我使用以下 jQuery 加载我们网站上的新闻页面,然后加载 iframe 中的相应文章。
var $news_story = $(window.location.hash.substring(1)),
$news_number = $news_story.selector,
$news_url = 'http://www.articleurlhere.com/ID=' + $news_number,
$news_url_default = 'http://www.main_news_feed_url_here.com';
var $url = location.pathname;
if ($news_number.length>0) {
$('#news-feed').attr('src', $news_url);
} else {
$('#news-feed').attr('src', $news_url_default);
}
当您从外部页面单击侧边栏链接时,这非常有用。但是,当您在新闻页面上单击侧边栏链接时,它不起作用(它将 URL 更改为与链接关联的 #number,但不会重新加载页面或在 iframe 中加载文章)。关于如何使这些链接在新闻页面上正常工作有什么想法吗?
最佳答案
我认为你需要像这样调用重新加载:
window.frames["news-feed"].location.reload();
关于jquery - 单击带有哈希标签的链接时强制刷新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4167382/