让按钮在另一个窗口中打开网页。

huangapple go评论79阅读模式
英文:

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.

&lt;button&gt;
    &lt;a href=&quot;producttest.html&quot;&gt;&lt;/a&gt;
&lt;/button&gt;

<br></br>
This might be what you want:

&lt;button onclick=&quot;window.open(&#39;producttest.html&#39;);&quot;&lt;/button&gt;

huangapple
  • 本文由 发表于 2023年4月10日 19:11:04
  • 转载请务必保留本文链接:https://go.coder-hub.com/75976565.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定