前端工作有很多地方需要页面跳转,有很多种实现方法,这里做一下归纳。
HTML标签
一般形式上可以用<a></a>
、<button></button>
、<input/>
:
<a href="链接">GO</a> <button onclick="window.location.href='链接'">GO</button> <input type="button" value="GO" onclick="location.href='链接'">
JS跳转页面代码
本页跳转
window.location.href = '链接'; window.location = '链接'; location.href = '链接'; location = '链接'; top.location = '链接';
新页跳转
window.open('链接'); open('链接');
或者在HTML标签中添加target="_blank"
:
<a href="链接" target="_blank">GO</a>
历史跳转
<a href="history.go(-1)">返回上一步</a> <a href="window.history.back()">返回上一步</a>