有没有可能制作一个链接到一页的网页,打开并定位在特定的文章中
Is it possible to make a link to a one page webpage to open and position itself at a specific article?
有没有一种方法可以通过外部链接打开特定文章,并在单页微信上打开链接时关注它?
我有一个网页,当你点击链接时,通过隐藏和显示div来显示内容。我想要的是以mywebpage/(div的名称)的形式创建一个指向我的网页的外部链接,并让该链接打开我的页面,但立即显示该div的内容,而不是单击普通的mywebpage链接时通常会看到的打开内容。
有可能吗?如何?
简短回答:是。
长话短说:你必须在页面加载时检查URL的哈希,并手动将其转换为隐藏或显示的div(或其他定位)。
当你在做的时候,当你的div打开和关闭时,你可以包括浏览器历史记录支持。
拆散我的一切http://www.tipmedia.com(段从页面源的第322行开始)
//on page ready
$(document).ready(function() {
//examine hash
if(window.location.hash == "#thanks") {
//scroll to an anchor tag, slight delay to insure correct page height
setTimeout(function() {
$('html,body').animate({scrollTop:$("#contact").offset().top}, 0);
},500);
//hide and show necessary divs
$("#contactThanks").css({"display":"block"});
$("#contactIndex").css({"display":"none"});
$("#contactGeneral").css({"display":"none"});
$("#contactMeeting").css({"display":"none"});
$("#contactCareers").css({"display":"none"});
//clear the hash (not necessary for your use)
window.location.hash = "";
}
}
历史记录也很简单,我使用了Modernizer.js来获得最佳的跨浏览器支持,但它看起来是这样的(非Modernizer的使用非常相似)
//during the hide/show of new content...
//if history is available
if(Modernizr.history) {
//this data is whatever it is you wish to save
lastPageState = { div:divName, pos:amount, page:lastLoadedPage };
history.pushState(lastPageState, divName.substring(1,divName.length-6), "index.html");
}
//...
//then later, the popsate event handler
window.onpopstate = function(event) {
//examine event.state and do whatever you need to
//example segment starts line 989
//Whatever data you saved would be read here and you would do the appropriate action,
//hiding or showing divs, reloading AJAX content, etc.
}
是的,您可以使用锚链接。因此,在目标页面中,用id命名div,比如div id="target"。然后在参考页面中使用以下形式的链接
参考页面:<a href="/mywebpage#target">GO to Target Info...</a>
目标页面:
<div id="target">
...content...
</div>
仅供参考-"target"只是一个示例名称,它可以是任何。。。
相关文章:
- 在Shopify中获取博客文章的图片
- 如何防止网页加载后自动启动功能
- 如何使用Node.js最有效地解析网页
- 刷新后保留对网页的更改
- 显示浏览量最高的三篇文章
- AJAX不会在文件上传后重定向到网页-POST方法
- 使用谷歌网站翻译器自动翻译网页
- 在我的网站上显示最近提交的文章/图片
- 如何在内联依赖项并将图像转换为dataURI的情况下完全提取网页
- 仅重新加载网页的一部分
- 每次提交表单时都会重新加载网页
- 打开网页后立即获取网页的活动javascript函数
- 链接两个网页或网络应用程序的最佳方式
- Android键盘不适用于包含Javascript的网页
- 网页上失败的javascript会导致所有其他脚本失败
- 在网页上显示当前股票报价
- HTML 5 和 3.js 代码不会在网页上显示任何内容
- 使用javascript替换网页上的文本
- 有没有可能制作一个链接到一页的网页,打开并定位在特定的文章中
- 如何在网页上为网页上的每一篇文章单独添加facebook分享按钮