[英]window.location.href in javascript just reloading page, not navigating to another website
我想使用按鈕從我的網站導航到另一個網站,這是我的代碼,我在這個項目中使用 React Bootstrap
<button onclick="window.location.href = 'https://www.glassdoor.com';">Click Here</button>
但是,當我單擊它時,它不會導航到新網站,它只會重新加載我所在網站的主頁。
window.location.href
返回當前頁面的href(URL)
因此,您可以刪除href
部分並簡單地設置您希望導航到的 url 的值。
<button onclick="window.location = 'https://www.glassdoor.com'">Click Here</button>
如果失敗,您也可以使用 function assign
<button onclick="window.location.assign('https://www.glassdoor.com')">Click Here</button>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.