如何在引导模式对话框中显示 URL:单击按钮 [英] How to show a URL in Bootstrap Modal dialog: On button click

查看:23
本文介绍了如何在引导模式对话框中显示 URL:单击按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须在模式窗口中加载页面(内部 URL).我一直在使用 window.showModalDialog(url, null, features) 但这在 Safari、Chrome 上无法正常工作.所以我们决定改用 Bootstrap 的模态对话框.我无法完成这项工作.有什么想法我可能做错了吗?

I have to load a page (internal URL) in a modal window. I had been using window.showModalDialog(url, null, features) but this does not work properly on Safari,Chrome. So we decided to use Bootstrap's modal dialog instead. I'm unable to make this work. Any ideas what I could be doing wrong?

    //imports
    <script src="http://code.jquery.com/jquery.js"></script>
    <script src="js/bootstrap.min.js"></script>
    <link href="css/bootstrap.min.css" rel="stylesheet">


    //activate content as modal
      $(document).ready(function(){
            $('#test_modal').modal({

                });
    }

    .......
    .......

    $("#btnSubmit").click(function(){
     var url = constructRequestURL();
      $('#test_modal').modal(data-remote=url,data-show="true");
    });


    -----
    -----
    <div class="modal fade" id="test_modal">
</div>

推荐答案

如果你打算继续引导路径,你可以看看这里:jsfiddle - Bootstrap 2.3.2 模式中的远程 URI

If you're going to continue down the bootstrap path, you could take a look here: jsfiddle - remote URI in Bootstrap 2.3.2 modal

请注意,该 URL 需要位于同一个域中(尽管您提到它是内部"),否则您的域需要被远程站点的 Access-Control-Allow-Origin 设置允许.所以请记住,小提琴演示实际上无法从 example.com 加载内容.

Note that the URL will need to be on the same domain (though you mentioned it is "internal") or your domain will need to be allowed by the remote site's Access-Control-Allow-Origin settings. So keep in mind that the fiddle demo can't actually load content from example.com.

<button type="button" class="btn" data-toggle="modal" data-target="#myModal" data-remote="http://example.com">Launch modal</button>

<div id="myModal" class="modal hide fade">
    <div class="modal-header">
        <button type="button" class="close" data-dismiss="modal" aria-hidden="true"> × </button>
        <h3 id="myModalLabel">Modal header</h3>
    </div>
    <div class="modal-body">
       <!-- remote content will be inserted here via jQuery load() -->
    </div>
    <div class="modal-footer">
        <button class="btn" data-dismiss="modal" aria-hidden="true">Close</button>
    </div>
</div>

您不需要为此编写任何自定义 JavaScript - Bootstrap 将根据 data-remote="http://example.com/whatever" 和 data-target=" 等数据属性知道要做什么#myModal"等.

You don't need to write any custom JavaScript for this - Bootstrap will know what to do based on the data-attributes like data-remote="http://example.com/whatever" and data-target="#myModal" etc.

有关详细信息,请参阅 引导模式文档 的相关部分...

See the relevant section of the Bootstrap modal docs for more info...

事实证明,动态更改远程 URL 并不像想象的那么容易.希望这个答案能进一步帮助你.

It turns out that changing the remote URL dynamically isn't as easy as it could be. Hopefully this answer will help you further.

这篇关于如何在引导模式对话框中显示 URL:单击按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆