這個問題在這里已經有了答案: 使用 JavaScript 在新視窗中打開 URL (3 個回答) 3 小時前關閉。
我正在做一個擴展,我想知道如何制作一個在新視窗中打開 URL 的按鈕?
這就是我現在擁有的但不多,我只從 HTML 開始
<head>
<style type="text/css">
body {
width: 380px;
height: 550px;
overflow: hidden;
background-image: url('Background Image');
}
</style>
</head>
<body>
<center>
<h1 style="color:white">Headline</h1>
</center>
</body>
<body>
<button onclick=href='https://url.com'type="button">
Link
</button>
<script>
function ClickButton() {
}
</script>
</body>
</html>```
uj5u.com熱心網友回復:
您可以使用 window.open(); https://developer.mozilla.org/en-US/docs/Web/API/Window/open
<button onClick="window.open('http://example.com', '_blank')">Open example in new tab</button>
uj5u.com熱心網友回復:
您可以:
- 編輯您的
<button>to<a>并添加target屬性:<a href="your-link.com" target="_blank">Link</a> - 使您的按鈕成為表單的一部分:
<form action="your-link.com" target="_blank"> <button type="submit">Go</button> </form> - 使用 EcmaScript 打開一張新卡片,使用
Window.open():<button onClick="window.open('your-link.com', '_blank')">
uj5u.com熱心網友回復:
您可以使用<a target='_blank' href='url/you/need'>style it like button</a>.
轉載請註明出處,本文鏈接:https://www.uj5u.com/gongcheng/324885.html
標籤:javascript html
