我有一个弹出窗口,当你点击一个链接时打开。我希望它的行为像Facebook图片或Pinterest弹出窗口,弹出窗口打开,网址改变,但没有重定向。
我的代码是:
<a href="/movies.jsp?id=123123" class="item-img">
<img src="/images/123123.jpg" />
</a>
<script>
$(document).on('click', '.item-img', function(e) {
e.preventDefault();
//code for popup
});
</script>
preventDefault
有助于防止重定向,但url不会改变。(使用Jquery)
怎样才能达到预期的效果?
发布于 2013-11-13 17:37:32
当您更改时,url...you将得到一个重定向。除非您正在实现使用散列更改url的单页应用程序(SPA) (这不会导致重定向)。
发布于 2013-11-13 17:42:33
您可能想要打开一个javascript弹出窗口:
$(document).on('click', '.item-img', function(e) {
e.preventDefault();
window.open(this.href, "self", 'width=200, height=300');
});
发布于 2013-11-13 22:19:37
我在这里找到了一些东西可以帮助你Popups like coderwall or facebook (url change but no redirect)
我认为这一切都是关于将条目推送到历史堆栈并显示弹出窗口
$(document).ready(function() {
$("a[rel=popup_link]").on("click", function(e){
e.preventDefault();
var url = $(e.target).attr("href");
//to get the ajax content and display in div with id 'content'
if(url != window.location){
window.history.pushState({path:url},'',url) ;
}
$.colorbox({
inline: true,
href: "<your content>",
open: true
});
});
});
Colorbox plugin
编辑:我只在IE上测试过它
https://stackoverflow.com/questions/19950170
复制相似问题