【问题标题】:Open bootstrap modal in new tab在新选项卡中打开引导模式
【发布时间】:2017-12-13 23:44:26
【问题描述】:

在单击middle mouse button 后是否可以在新标签中打开bootstrap modal(或者只需单击项目上的right mouse buttonclick“在新标签中打开”)?

预期行为:

用户可以通过单击项目上的left mouse button 在同一选项卡中打开模式。用户也可以点击middle mouse button(滚动条)在新标签页中打开模式。

我可以做类似的事情(下面的链接),但我无法处理 modal 的情况,甚至有可能以某种方式将模式传递到新选项卡吗?

JSFiddle:http://jsfiddle.net/vqxf7zyk/1/

(而不是重定向到谷歌,标签中应该有新的模式)

解决方案(基于@RohitSharma 答案):

http://jsfiddle.net/vqxf7zyk/10/

【问题讨论】:

    标签: twitter-bootstrap-3 modal-dialog vue.js bootstrap-modal vuejs2


    【解决方案1】:

    你可以使用它。它工作正常。

    $(document).ready(function() {
      $('.btn-info.btn-lg').mousedown(function(event) {
        if (event.which == 2) {
          event.preventDefault();
          window.open(document.URL + '#myModal', '');
        }
      });
      $(window).load(function() {
        $(window.location.hash).modal("show");
      });
    });
    
    function openModal() {
      window.open(document.URL + '#myModal', '');
      $(window.location.hash).modal("show");
    }
    <link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
    <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <!-- Trigger the modal with a button -->
    <button type="button" class="btn btn-info btn-lg" data-toggle="modal" data-target="#myModal" contextmenu="mymenu">Open Modal</button>
    
    
    <!-- menu will work only in firefox -->
    <menu type="context" id="mymenu">
      <menuitem label="Open this modal in new tab" onclick="openModal()" icon="/images/refresh-icon.png"></menuitem>
    </menu>
    
    <!-- Modal -->
    <div id="myModal" class="modal fade" role="dialog">
      <div class="modal-dialog">
    
        <!-- Modal content-->
        <div class="modal-content">
          <div class="modal-header">
            <button type="button" class="close" data-dismiss="modal">&times;</button>
            <h4 class="modal-title">Modal Header</h4>
          </div>
          <div class="modal-body">
            <p>Some text in the modal.</p>
          </div>
          <div class="modal-footer">
            <button type="button" class="btn btn-default" data-dismiss="modal">Close</button>
          </div>
        </div>
    
      </div>
    </div>

    在新标签页中打开 URL 时,我使用了模态框的 ID 来添加 URL。并使用window.location.hash打开模态得到相同的ID。

    我没有在上下文菜单中找到任何链接以在新选项卡中打开模式,因此我手动添加了上下文菜单。这只适用于 Firefox,您可以在 w3schools.comread more 了解它。

    如果您想让您的网站浏览器兼容,您可以使用自定义上下文菜单。

    目前,您可以在所有浏览器上尝试此示例以进行中键单击,而在 Firefox 中仅用于上下文菜单

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2021-01-20
      • 1970-01-01
      • 2013-10-10
      • 1970-01-01
      • 2020-09-02
      • 1970-01-01
      • 1970-01-01
      • 2018-05-07
      相关资源
      最近更新 更多