英文:
Make a button open a webpage in another window
问题
你可以尝试将锚链接放在按钮内部,像这样:
<li class="card-action-item">
<a target="_blank" rel="noopener noreferrer" href="producttest.html">
<button class="card-action-btn" aria-labelledby="card-label-1">
<ion-icon name="cart-outline"></ion-icon>
</button>
</a>
<div class="card-action-tooltip" id="card-label-1">Open In New Tab</div>
</li>
这将使按钮内的文本成为可点击的链接,打开一个新标签页,并且rel
属性帮助确保安全性。
英文:
This is the code I have:
<ul class="card-action-list">
<li class="card-action-item">
<button class="card-action-btn" aria-labelledby="card-label-1">
<ion-icon name="cart-outline"></ion-icon>
</button>
<div class="card-action-tooltip" id="card-label-1">Open In New Tab</div>
</li>
<li class="card-action-item">
<button class="card-action-btn" aria-labelledby="card-label-1">
<ion-icon name="cart-outline"></ion-icon>
</button>
<div class="card-action-tooltip" id="card-label-2">Open In New Window</div>
</li>
<li class="card-action-item">
<button class="card-action-btn" aria-labelledby="card-label-2">
<ion-icon name="share-social-outline"></ion-icon>
</button>
<div class="card-action-tooltip" id="card-label-3">Share Link</div>
</li>
</ul>
I want to put an anchor into the button kinda like this:
<a target="_blank" and rel="noopener noreferrer" href="producttest.html"></a>
When I put it into the button thought it does not work. Sorry if this a simple fix, I am new to Webdevelopment
答案1
得分: 0
如果您将锚点放在按钮内部(下面是第一个代码),您将不会获得按钮点击的视觉效果,但会获得点击锚点时的效果。
<button>
<a href="producttest.html"></a>
</button>
这可能是您想要的:
<button onclick="window.open('producttest.html');"></button>
英文:
If you put the anchor inside the button (first code below), you won't get the visual effect of a button click, but that one from when you click an anchor.
<button>
<a href="producttest.html"></a>
</button>
<br></br>
This might be what you want:
<button onclick="window.open('producttest.html');"</button>
通过集体智慧和协作来改善编程学习和解决问题的方式。致力于成为全球开发者共同参与的知识库,让每个人都能够通过互相帮助和分享经验来进步。
评论