[英]Proper way to mark up HTML to allow for right click “open in a new tab” option in context menu
I have searched around but no question seems to address this concern.我四处搜索,但似乎没有任何问题可以解决这个问题。
I have the following markup:我有以下标记:
<li>
<div class="box-brochure-slide" onclick="window.location='product.php?item=TEC%2FSR-888HP-SS';">
<div class="boxInner-item">
<div class="triangle-topright-cover"></div>
<div class="triangle-topright-red"></div>
<div class="label-limitedsets">LIMITED SETS</div>
<img class="lazy" alt="" src="img/pixel.png" data-original="user/picture/TEC-SR-888HP-SS.jpg">
<div class="ui content">
<div class="productbrand">TECNO</div>
<div class="productname">TECNO SR-888HP-SS 2 X HI POWER BURNERS, 1 X MED BURNER, <br>BATTERY AUTO IGNITION</div>
<div class="price">
<div class="specialprice"><div class="specialprice-name">Crazy Price</div><span class="pricecurrency">$</span>488<span class="pricecents">00</span></div>
<div class="usualprice">U.P. $588.00</div>
</div>
</div>
</div>
</div>
</li>
However, when I try to right click on the <li>
on the web page, there was not an option for me to open in a new tab.但是,当我尝试右键单击网页上的<li>
时,我没有在新选项卡中打开的选项。 What is wrong with the markup here?这里的标记有什么问题?
Edit: I have read in some sources that <a>
would solve the problem, but I do not wish to wrap the entire <li>
in an anchor tag.编辑:我在一些资料中读到<a>
可以解决问题,但我不希望将整个<li>
包装在锚标记中。 Is there a way to do this?有没有办法做到这一点?
Note: I do not wish to right click to OPEN in a new tab.注意:我不希望右键单击以在新选项卡中打开。 I just wish to have an option available to open in a new tab when I right click on it.我只是希望有一个选项可以在我右键单击它时在新选项卡中打开。
虽然您不想使用该元素,但如果您将最上面的 div 替换为“a”,而保持类 ID 和 css 不变,您也将获得与“在新标签页中打开”选项相同的外观。
To Open in new tab on right click first we need to check the mouse click event and then open the link.要首先右键单击在新选项卡中打开,我们需要检查鼠标单击事件,然后打开链接。
<div id="open">open</div>
$('#open').mousedown(function(event) {
if(event.which == 3) { //Right click event
window.open('http://google.com','_newtab'); // To open in new tab
} else{
alert('Please Right click to open');
}});
为此,您需要使用<a>
标签并将href
属性传递给标签
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.