[英]How to open a new window when i click one button?
我正在學習 javascript 並且我使用 Visual Studio 代碼和 node.js 我想創建一個記錄器,當按下按鈕時我需要打開一個新的 window 我真的很想知道我該怎么做。 當我按下按鈕時我有這個代碼並且什么也沒發生。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Fondo-Imagen</title>
<link rel="stylesheet" href="estilo.css">
</head>
<body>
<div class="signin">
<form>
<h2 style="color:rgb(177, 114, 63)"> Log In</h2>
<input type="text" name = "rol" placeholder="Rol" style="color:rgb(177, 114, 63)">
<input type="text" name = "username" placeholder="Username" style="color:rgb(177, 114, 63)">
<input type="password" name = "pass" placeholder="Password" style="color:rgb(177, 114, 63)">
<br><br>
<button href=""><input type="button" style="color:rgb(177, 114, 63); background-color:
white;" value="Log In"></button><br>
<br>
<div id="container">
<a href="#" style="color:rgb(177, 114, 63); margin-right:0px; font-size: 13px;
font-family: Tahoma, Geneva, sans-serif;">Reset password</a>
</div><br><br><br><br><br><br>
<a href="#" style="color:rgb(177, 114, 63)"> Sing Up</a>
</form>
</div>
<script>
let button= document.querySelector('button');
button.addEventListener('click', (ev)=>{
let ref= window.open('new.html','lobby',options);
});
</script>
</body>
</html>
window.open('new.html','_blank');
上面的代碼將幫助您打開一個空白的新標簽。
很多方法可以做到這一點,一些技術在這里:
<button onclick="window.open('https://www.our-url.com')" id="myButton" class="btn request-callback" >Explore More </button>
您也可以使用錨標記而不是按鈕來執行此操作,因為 href 不是按鈕標記的屬性,如下所示:
<a href="new.html" target="_blank"><input type="button" style="color:rgb(177, 114, 63); background-color: white;" value="Log In"></a><br>
或者你也可以這樣做:試試這個。 這將導航到點擊鏈接。
<button onclick="window.location.href='http://www.stackoverflow.com'">click me</button>
您需要彈出窗口還是新標簽? If you need a pop up you can either use a modal with jquery or with pure create a hidden div in your html and on click remove class hidden with Javascript. 如果您想在新標簽頁中打開,只需添加<a href="" target="_blank" > Your Link </a>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.