[英]How to redirect from a normal JavaScript page to angular 6(microsite to angular 6)?
我只是希望我的登陸屏幕用普通的 JavaScript 構建,以減少負載並在點擊登陸屏幕中的任何按鈕時重定向到我的 angular 6 應用程序。
如何從index.html
重定向到另一個(Angular) index.html
。
假設您的頁面上有多個按鈕,您可以為所有按鈕觸發重定向,如下所示:
var buttons= document.getElementsByTagName('button'); for (var i = 0; i < buttons.length; i++) { var button = buttons[i]; button.onclick = function() { window.location.href = "https://google.de"; } }
<button>Button 1</button> <button>Button 2</button> <button>Button 3</button>
您可以通過調用window.location.replace()
方法或更新window.location.href
屬性的值來完成此操作。
調用window.location.replace()
方法模擬 HTTP 重定向,更新window.location.href
屬性的值模擬用戶單擊鏈接。
您可以將它們用作:
// similar behaviour as an HTTP redirect
window.location.replace("index.html");
或者:
// similar behaviour as clicking on a link
window.location.href = "index.html";
您還可以創建一個隱藏鏈接並觸發點擊它,如下所示:
<a href="index.html" style="display: none"></a>
<script type="text/javascript">
document.getElementsByTagName("a")[0].click();
</script>
如果您希望鏈接在新選項卡中打開,您可以使用target="_blank"
屬性,如下所示:
<a href="index.html" style="display: none" target="_blank"></a>
祝你好運。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.