【问题标题】:How to show a modal on a new window using jQuery如何使用 jQuery 在新窗口上显示模式
【发布时间】:2018-10-05 18:55:34
【问题描述】:

所以我一直试图在新窗口上显示模态,直到现在我使用

$('#myModal').modal('show');

将其显示为自定义窗口,但我想打开一个新的浏览器窗口并在其中打印模式。

我想这样做是因为如果我只使用modal('show'); 并且我的父页面在后台刷新,(我正在使用window.location.reload(true); 来刷新父页面,这就是它关闭模式的原因,我不能'找不到如何使用 ajax 刷新整个父页面)它将关闭模式窗口,我不想要这个。

有什么功能可以用来在新窗口中打开模态框吗?

【问题讨论】:

  • 为什么你不在页面加载中调用这个?
  • 因为我需要调用一个javascript函数并将数据传递给模态并显示它。
  • 我可以看到如何测试打开是否已打开,以便每次重新加载时都显示它
  • 如果对你有帮助,可以参考链接stackoverflow.com/questions/40847454/…

标签: javascript jquery ajax


【解决方案1】:

我创建了 2 个文件; 文件 1 有这个代码,

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Bootstrap Example</title>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <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/3.3.1/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    </head>
    <body>
        <div class="container">
            <button type="button" class="btn btn-info btn-lg" onclick="window.open('file:///C:/Users/Admin/Desktop/a.html'); ">Open Modal</button>
        </div>
    </body>
</html>

第二个文件有这个代码

<!DOCTYPE html>
<html lang="en">
    <head>
        <title>Bootstrap Example</title>
        <meta charset="utf-8">
        <meta name="viewport" content="width=device-width, initial-scale=1">
        <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/3.3.1/jquery.min.js"></script>
        <script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    </head>
    <body>
        <div class="container">
            <div class="modal fade" id="myModal" role="dialog">
                <div class="modal-dialog">
                    <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>
        </div>
        <script type="text/javascript">
            $("#myModal").modal();
        </script>
    </body>
</html>

因为这行得通,试试这个。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-07-04
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多