Window.showModalDialog() 在 for 循环 JavaScript 中不起作用

发布于 2025-01-13 08:49:15 字数 4262 浏览 1 评论 0原文

我试图在 for 循环中引入 showModaldialog,我更改了 id 的名称,这样,不同的是,它可以根据用户请求打开任意多次:

for (i = 0; i < number; i++) { 
    cerrado=0;
    cerrado =  window.showModalDialog(ventana, 'url' ,'nuevadiag'+id);

    if (cerrado==null){
        i=numero;
    }
}

问题是它只打开一次,没有其他任何内容想法?,这是window.showModalDialog()的jquery函数:

(function() {
    window.spawn = window.spawn || function(gen) {
        function continuer(verb, arg) {
            var result;
            try {
                result = generator[verb](arg);
            } catch (err) {
                return Promise.reject(err);
            }
            if (result.done) {
                return result.value;
            } else {
                return Promise.resolve(result.value).then(onFulfilled, onRejected);
            }
        }
        var generator = gen();
        var onFulfilled = continuer.bind(continuer, 'next');
        var onRejected = continuer.bind(continuer, 'throw');
        return onFulfilled();
    };
    window.showModalDialog = window.showModalDialog || function(pantalla, url, arg, opt,id) {
        //documento= window.parent.parent.document;
//      alert(pantalla);
        documento= pantalla.document;
//      alert(documento.body);
        url = url || ''; //URL of a dialog
        arg = arg || null; //arguments to a dialog
        opt = opt || 'dialogWidth:300px;dialogHeight:200px;color:#ff6600;'; //options: dialogTop;dialogLeft;dialogWidth;dialogHeight or CSS styles
        opt = opt+ ';color:#ff6600;';
        var caller = '';
        if(arguments.callee.caller != null ){
            caller = arguments.callee.caller.toString();
        }
        var dialog = documento.body.appendChild(document.createElement('dialog'));
        dialog.setAttribute('style', opt.replace(/dialog/gi, ''));
        dialog.setAttribute('id',id );
        var idDialogClose="dialog-close"+id;
        
        var idDialogBody = 'dialog-body';
        if( id!=undefined && id!=null && id!=''){
            var idDialogBody ='dialog-body'+id;
        }
        
        dialog.innerHTML = '<a href="#" id="'+idDialogClose+'" style="position: absolute; top: 0; right: 5px; font-size: 20px; color: #000; text-decoration: none; outline: none;">&times;</a><iframe id="'+idDialogBody+'" src="' + url + '" style="border: 0; width: 100%; height: 100%;border-top: 3px solid #ff6600;border-bottom: 3px solid #ff6600;border-left: 3px solid #ff6600;border-right: 3px solid #ff6600;margin-right: -10px;margin-bottom: -10px;"></iframe>';
        documento.getElementById(idDialogBody).contentWindow.dialogArguments = arg;
        documento.getElementById(idDialogClose).addEventListener('click', function(e) {
            e.preventDefault();
            dialog.close();
        });
        
        dialog.showModal();
        //if using yield or async/await
        if(caller.indexOf('yield') >= 0 || caller.indexOf('await') >= 0) {
            return new Promise(function(resolve, reject) {
                dialog.addEventListener('close', function() {
                    var returnValue = documento.getElementById(idDialogBody).contentWindow.returnValue;
                    documento.body.removeChild(dialog);
                    //resolve(returnValue);
                });
            });
        }
        //if using eval
        var isNext = false;
        var nextStmts = caller.split('\n').filter(function(stmt) {
            if(isNext || stmt.indexOf('showModalDialog(') >= 0)
                return isNext = true;
            return false;
        });
        dialog.addEventListener('close', function() {   
            var returnValue = documento.getElementById(idDialogBody).contentWindow.returnValue;
            documento.body.removeChild(dialog);
            
            alert('returnValue: '+returnValue);
            alert('nextStmts: '+nextStmts);
            alert('nextStmts[0]: '+nextStmts[0]);
            alert('nextStmts[1]: '+nextStmts[1]);

            nextStmts[0] = nextStmts[0].replace(/(window\.)?showModalDialog\(.*\)/g, JSON.stringify(returnValue));

        });
        throw 'Execution stopped until showModalDialog is closed';
    };  
})();

谢谢! BR。

I am trying to introduce showModaldialog in a for loop, I have changed the names of the id's so that, being different, it can be opened as many times as the user requests:

for (i = 0; i < number; i++) { 
    cerrado=0;
    cerrado =  window.showModalDialog(ventana, 'url' ,'nuevadiag'+id);

    if (cerrado==null){
        i=numero;
    }
}

the problem is that it only opens once and nothing else, any ideas?, this is the jquery function of window.showModalDialog():

(function() {
    window.spawn = window.spawn || function(gen) {
        function continuer(verb, arg) {
            var result;
            try {
                result = generator[verb](arg);
            } catch (err) {
                return Promise.reject(err);
            }
            if (result.done) {
                return result.value;
            } else {
                return Promise.resolve(result.value).then(onFulfilled, onRejected);
            }
        }
        var generator = gen();
        var onFulfilled = continuer.bind(continuer, 'next');
        var onRejected = continuer.bind(continuer, 'throw');
        return onFulfilled();
    };
    window.showModalDialog = window.showModalDialog || function(pantalla, url, arg, opt,id) {
        //documento= window.parent.parent.document;
//      alert(pantalla);
        documento= pantalla.document;
//      alert(documento.body);
        url = url || ''; //URL of a dialog
        arg = arg || null; //arguments to a dialog
        opt = opt || 'dialogWidth:300px;dialogHeight:200px;color:#ff6600;'; //options: dialogTop;dialogLeft;dialogWidth;dialogHeight or CSS styles
        opt = opt+ ';color:#ff6600;';
        var caller = '';
        if(arguments.callee.caller != null ){
            caller = arguments.callee.caller.toString();
        }
        var dialog = documento.body.appendChild(document.createElement('dialog'));
        dialog.setAttribute('style', opt.replace(/dialog/gi, ''));
        dialog.setAttribute('id',id );
        var idDialogClose="dialog-close"+id;
        
        var idDialogBody = 'dialog-body';
        if( id!=undefined && id!=null && id!=''){
            var idDialogBody ='dialog-body'+id;
        }
        
        dialog.innerHTML = '<a href="#" id="'+idDialogClose+'" style="position: absolute; top: 0; right: 5px; font-size: 20px; color: #000; text-decoration: none; outline: none;">×</a><iframe id="'+idDialogBody+'" src="' + url + '" style="border: 0; width: 100%; height: 100%;border-top: 3px solid #ff6600;border-bottom: 3px solid #ff6600;border-left: 3px solid #ff6600;border-right: 3px solid #ff6600;margin-right: -10px;margin-bottom: -10px;"></iframe>';
        documento.getElementById(idDialogBody).contentWindow.dialogArguments = arg;
        documento.getElementById(idDialogClose).addEventListener('click', function(e) {
            e.preventDefault();
            dialog.close();
        });
        
        dialog.showModal();
        //if using yield or async/await
        if(caller.indexOf('yield') >= 0 || caller.indexOf('await') >= 0) {
            return new Promise(function(resolve, reject) {
                dialog.addEventListener('close', function() {
                    var returnValue = documento.getElementById(idDialogBody).contentWindow.returnValue;
                    documento.body.removeChild(dialog);
                    //resolve(returnValue);
                });
            });
        }
        //if using eval
        var isNext = false;
        var nextStmts = caller.split('\n').filter(function(stmt) {
            if(isNext || stmt.indexOf('showModalDialog(') >= 0)
                return isNext = true;
            return false;
        });
        dialog.addEventListener('close', function() {   
            var returnValue = documento.getElementById(idDialogBody).contentWindow.returnValue;
            documento.body.removeChild(dialog);
            
            alert('returnValue: '+returnValue);
            alert('nextStmts: '+nextStmts);
            alert('nextStmts[0]: '+nextStmts[0]);
            alert('nextStmts[1]: '+nextStmts[1]);

            nextStmts[0] = nextStmts[0].replace(/(window\.)?showModalDialog\(.*\)/g, JSON.stringify(returnValue));

        });
        throw 'Execution stopped until showModalDialog is closed';
    };  
})();

thanks!
BR.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文