
在日常开发中,如果我们在当前页面需要刷新打开新的页面,或者涉及到当前页面跳转的问题,我们该如何解决呢?其实我们可以需要刷新当前页面或者覆盖当前页面,在当前页面打开新的地址。
一、在当前页面打开新的页面实现过程:
1、需要刷新当前页面或者覆盖当前页面,当前页面打开新的地址。
1 | window.open( 'http://www.baidu.com' , '_self' );
|
2、如果在a标签中进行跳转那么就是用到了target,当前页面打开。
1 | <a href= "http://www.baidu.com" class = "class1" target= "_self" >
|
二、具体实现代码:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 | <html>
<head>
<meta http-equiv= "Content-Type" content= "text/html;charset = gb2312" />
</head>
<body>
<script type= "text/javascript" >
function on(html){
window.open(html, '_self' )
}
</script>
<input type= "button" οnclick= "on('sdkjf')" value= "sdfkgh" >
</body>
</html>
|
以上就是用js在当前页面打开新页面的实现过程和具体实现代码,希望可以对你有所帮助哦~