[英]How to redirect to another html page without using window.location?
[英]How to redirect without using window.location
如果我单击页面 A 中的按钮,浏览器将重定向到页面 B。在页面 B 中,如果我再次单击另一个按钮,它将重定向到页面 A。这里我使用window.location.href
重定向新页面。
例如: window.location.href="http:\\\\localhost:12345\\index2.html"
是重定向下一页的任何其他替代方法。 我不想使用windows.location
更新:
如果我使用windows.location
,我来自的 url 存储在document.reffer
。 出于安全目的,我不想允许存储 url。
您可以使用此方法示例:-
function myFunction() { location.assign("https://www.google.co.in"); }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.7.2/jquery.min.js"></script> <!DOCTYPE html> <html> <body> <button onclick="myFunction()">Load new document</button> </body> </html>
你也可以使用
window.location.replace("http://someUrl.com");
replace() 不会在会话历史记录中保留原始页面。
在 angularjs 中使用$location
:请参阅文档https://docs.angularjs.org/api/ng/service/$location
$url =$('<a/>')
$url.attr('href',"http://google.com");
$url[0].click()
你可以试试这个。
您可以使用location.assign()重定向另一个页面。
location.assign("https://www.facebook.com/");
为什么不使用<a>
。 你唯一要做的就是给它一个类似按钮的类。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.