javascript - 使用适用于所有浏览器的 jQuery 或 Javascript 创建弹出框

标签 javascript jquery html css popupwindow

我有一个类似下面的代码,它在我的 chrome 浏览器中正确显示弹出消息,但我已经在其他浏览器(如 Firefox 和 Edge)上测试了它,这不起作用,它只是在页面的末尾...代码是:

var iframe = document.createElement("IFRAME");
        iframe.setAttribute("src", 'data:text/plain,');
        document.documentElement.appendChild(iframe);
        if(window.frames[0].window.confirm("Are you sure you want to change brand state? Note: Changing brand state from Preview to Live will erase all data related to that brand.")) {
            $.post("/brand/updateBrandState", {
                'brandId': $(this).val(),
                "brandState": $(this).find("option:selected").text()
            }, function (data) {
                if (data == "ok") {
                    window.location.reload(true);
                }else if(data=="empty") {
                    alert("Cannot change state from Live to Preview");
                    window.location.reload(true);
                }else if(data=="live") {
                    alert("Brand is now live!");
                }
            });

有人可以帮我让它在其他浏览器上也能工作吗??

谢谢!!

编辑:

现在我正在使用这个 html:

 <div id="dialog" title="Basic dialog"> 
<p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p> 
</div>

最佳答案

对于弹出框,使用jQuery Dialog .所有浏览器(支持 jquery)易于使用和支持。

演示

$("#myDialog").dialog({
    resizable: false,
    height: 140,
    modal: true,
    buttons: [
        {
            text: "Yes",
            click: function () {
                $(this).dialog("close");
                //Do some Job
            },
        },
        {
            text: "No",
            click: function () {
                $(this).dialog("close");
            },
        }

    ],
    open: function (event, ui) {
    //add some functionality or styling if you want
    },
    //same for close,drag,dragStart,dragStop,focus and all
});

希望对您有所帮助。

关于javascript - 使用适用于所有浏览器的 jQuery 或 Javascript 创建弹出框,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/37970175/

相关文章:

javascript - Observable<QuerySnapshot<DocumentData>> 类型上不存在属性 'then'

javascript - 使用 Jquery 确定页面上元素位置的方法

javascript - MySQLi + PHP - 获取字段的结果

jquery - 如何使用 jquery datatable 显示来自 url 的 API 数据

javascript - 使用 javascript 发送后变量?

javascript - FBML 是否符合 HTML 标准?

javascript - Fancybox 将值传递给弹出框

javascript - 如何解析 ajax 返回的字符串的 JSON 列表?

jquery - 表单提交时获取所有已检查的 iCheck 输入值

javascript - 谷歌图表 : hi is not a function