微信为什么不支持window.showModalDialog?

微信公众号开发一个页面,点击按钮需要弹出子窗口,js使用window.showModalDialog方式,在浏览器上没问题,从微信公众号菜单进去后,点击按钮没反应,微信不支持window.showModalDialog这种方式,有没有解决方案?

页面禁止了或者不支持API

你想手机上弹出一个对话框页面是多么的不搭调。

你完全可以用弹出层或者基于这一原理的库代替。

因为微信用的是一套自己的浏览器

浮动层+iframe来模拟,在手机上showModalDialog和window.open一个样。。微信应该是禁用这个js API了。。

 <!DOCTYPE html><style>
#pop{position:fixed;width:100%;height:100%;left:0;top:0;display:none;background:#fff;border:solid 1px #666}
#pop iframe{width:100%;height:100%;display:block}
#pop a.close{position:absolute;top:0px;right:0px;background:#f00;color:#fff;line-height:20px;padding:0 10px}
</style>
<script>
    function showLayer(url) {
        var pop = document.getElementById('pop'), ifr = pop.getElementsByTagName('iframe')[0];
        pop.style.display = 'block';
        ifr.src = url;
    }
</script>
<div id="pop"><iframe frameborder="0" marginheight="0" marginwidth="0"></iframe><a href="javascript:void(0)" onclick="this.parentNode.style.display='none';" class="close">关闭</a></div>
<input type="button" onclick="showLayer('http://avatar.csdn.net/C/E/2/2_yinzhijiessh.jpg')" value="打开yinzhijiessh.jpg" />

你想手机上弹出一个对话框页面是多么的不搭调。

你完全可以用弹出层或者基于这一原理的库代替。