简体   繁体   English

我可以打开未选择默认选项卡的新窗口(网页)吗?

[英]Can I open a new window(web page) who not default tab selected

在此处输入图片说明

For example, assuming that the same tab as the above image exists, the 'Active' tab is specified as default. 例如,假设存在与上图相同的选项卡,则将“活动”选项卡指定为默认选项。

However, my client wishes to keep this default option and open a new window that different tab will selected.(second 'Link' tab or something.) 但是,我的客户希望保留此默认选项并打开一个新窗口,该窗口将选择其他选项卡(第二个“链接”选项卡或其他内容)。

Is this possible? 这可能吗? If it can, how to do this? 如果可以,该怎么办?

assuming you are using Bootstrap, you can remove all the attributes related to tab behavior from the a.nav-link and instead use target:"_blank" . 假设您使用的是Bootstrap,则可以从a.nav-link删除所有与选项卡行为相关的属性,而可以使用target:"_blank" Here in bellow example I have made added the New Page tab, there I have removed all the extra attributes and added target attribute. 在下面的示例中,我添加了“ New Page选项卡,在此删除了所有多余的属性并添加了target属性。

This example may not work within this snippet since it is within the nested frame, and opening the _blank tab from nested tab would be messy, but it works on web page I have tested it. 此示例可能无法在此代码段中使用,因为它位于嵌套框架中,并且从嵌套选项卡中打开_blank选项卡会很麻烦,但是它在我测试过的网页上有效。

 <link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous"> <script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script> <script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.14.3/umd/popper.min.js" integrity="sha384-ZMP7rVo3mIykV+2+9J3UJ46jBk0WLaUAdn689aCwoqbBJiSnjAK/l8WvCWPIPm49" crossorigin="anonymous"></script> <script src="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/js/bootstrap.min.js" integrity="sha384-ChfqqxuZUCnJSK3+MXmPNIyE6ZbWh2IMqE241rYiqJxyMiZ6OW/JmZQ5stwEULTy" crossorigin="anonymous"></script> <ul class="nav nav-tabs" id="myTab" role="tablist"> <li class="nav-item"> <a class="nav-link active" id="home-tab" data-toggle="tab" href="#home" role="tab" aria-controls="home" aria-selected="true">Home</a> </li> <li class="nav-item"> <a class="nav-link" id="profile-tab" data-toggle="tab" href="#profile" role="tab" aria-controls="profile" aria-selected="false">Profile</a> </li> <li class="nav-item"> <a class="nav-link" id="contact-tab" data-toggle="tab" href="#contact" role="tab" aria-controls="contact" aria-selected="false">Contact</a> </li> <li class="nav-item"> <a class="nav-link" href="https://stackoverflow.com/" target="_blank">New Page</a> </li> </ul> <div class="tab-content" id="myTabContent"> <div class="tab-pane fade show active" id="home" role="tabpanel" aria-labelledby="home-tab">Home Page</div> <div class="tab-pane fade" id="profile" role="tabpanel" aria-labelledby="profile-tab">Profile Page</div> <div class="tab-pane fade" id="contact" role="tabpanel" aria-labelledby="contact-tab">Contact Page</div> </div> 

Assuming that you have div contains tab contents. 假设您的div包含选项卡内容。

<ul class="nav nav-tabs" id="myTab" role="tablist">
<li class="nav-item">
    <a class="nav-link" id="link1" data-toggle="tab" href="?section=tab1">Tab 1</a>
</li>
<li class="nav-item">
    <a class="nav-link" id="link2" data-toggle="tab" href="?section=tab2">Tab 2</a>
</li></ul>

Pass your div id as parameter section as href of li . 通过您div id作为参数section为HREF li

<div id="tab1">
</div>
<div id="tab2">
</div>

Then get the parameter, and scroll manually to the div . 然后获取参数,并手动滚动到div

<script>
    const params = new URLSearchParams(window.location.search);
    const section = params.get('section');

    if(section!=''){
        $('#' + section).addClass('active');
        $('html, body').animate({
            scrollTop: $('#' + section).offset().top
        }, 2000);
    }else{
        //Default tab here
        $('#tab1').addClass('active');
        $('html, body').animate({
            scrollTop: $('#tab1').offset().top
        }, 2000);
    }
</script>

Hope this would help. 希望这会有所帮助。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 window.open(url)在同一选项卡中未打开新网页 - window.open(url) not opening new web page in the same tab 当我右键单击选定的选项卡并在新选项卡上打开它时,它总是打开默认的活动选项卡 - when i right click on selected tab and open it on new tab ,it always open the default active tab 我是否可以操纵网页以避免打开新标签,并在同一标签中显示内容? - Can I manipulate a web page to avoid open a new tab, and display the content in the same tab? 如何在单击链接时打开新选项卡或窗口? - How can I open a new tab or window when a link is clicked? window.open在新标签页而不是弹出窗口中打开页面 - window.open open the page in a new tab instead of in popup window 在新标签页/窗口中打开页面,并将当前窗口定向到新网址 - Open page in new tab/window AND direct current window to a new url 如何在新窗口中而不是同一窗口及其新选项卡中打开页面? - How to open page in new window and not in same window and on its new tab? 如何确定页面是否在新窗口或新标签页中加载? - How can I determine if the page is loaded in a new window or tab? 如何保持同一页面并自动打开新标签页 - How can I stay on same page and open a new tab automatically 如何在新页面或新标签页中打开此javascript? - How can i open this javascript in new page or tab?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM