首页 > 解决方案 > 单击指向超链接的按钮时,如何避免原始页面转到不同的页面?

问题描述

注意:我希望我的链接在新选项卡中打开,但将其保留在原始选项卡所在的位置。然而,原来的标签会导致不同的地方?

        .btn {
            background-color: transparent;
            border-radius: 28px;
            border: 1px solid #0762C8;
            display: inline-block;
            cursor: pointer;
            color: #0762C8;
            font-family: Tahoma;
            font-size: 14px;
            padding: 4px 13px;
            text-decoration: none;
            position: absolute;
            margin-top: -10%;
        }
    
        .btn:hover {
            background-color: #0762C8;
            border-color: #0762C8;
        }
    
        .btn:active {
            position: relative;
            top: 1px;
        }
    
        .flex-container {
            display: flex;
            justify-content: center;
        }
    <div class="col-12 col-md-6 col-lg-4 py-3 text-center border"><a
                        href="http://www.example.net/" target="_blank"
                        ><img class="img-fluid" font-family:lucida="" sans=""
                            src="/images/contentimages/images/Giveaways.png" /></a>
    
                    <p class="my-3" style="font-size:18px;">&nbsp;</p>
    
                    <div class="flex-container"><a class="btn btn-info btn-sm edatalayer order-1" onclick=" window.open('http://www.example.net/','_blank')"
                            data-list="product-listing-page" data-position="1" data-purl="custom-business-forms"
                            >Giveaways <i class="far fa-chevron-right pl-1"></i></a></div>
                </div>

标签: htmlcssbuttonhyperlinktabs

解决方案


您可以使用onclick

<a href="https://example.com" onclick="window.open('#','_blank');window.open(this.href,'_self');">

推荐阅读