有个折中的办法
// 例子, 比如index.html
转向例子#example, iframe.hidden {
display:none;
}
$().ready(function(){
$("#example").show();
$(document.body).on('click', 'a[rel~="hide_ref"]',function(){
var url = '/redirect.html#!'+ encodeURI(this.href);
$('').appendTo($(document.body));
return false;
});
});
// 这个是中间文件, redirect.html
var hash = location.hash;
location.hash = '';
if(hash.substring(0,2)==='#!') {
var url = decodeURI(hash.substring(2));
top.location.href = url;
}
这样只要点击rel里带hide_ref里链接, 都会生成一个iframe, iframe里读取location.hash(再重置), 然后top.location.href做转向, 无论从哪个地址点过去, 都是那个iframe的url