创建 javascript 弹出窗口的最优雅方式?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/6787258/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-25 21:52:25  来源:igfitidea点击:

most elegant way to create a javascript popup?

javascript

提问by Steven

Is there a more elegant way of creating a JavaScript popup?

有没有更优雅的方式来创建 JavaScript 弹出窗口?

<head>
<script>
function myPopup() { window.open( "http://www.google.com", "myWindow", "status=1, height=300, width=300, resizable=0" )
}
</script>
</head>

<body>
<input type="button" onClick="myPopup()" value="popup">
</body>

采纳答案by Clayton

jQuery UI has a great modal dialogplugin that is easy to use.

jQuery UI 有一个很棒的模态对话框插件,易于使用。

回答by Paul

<head>
  <script>
    function myPopup(){ 
        window.open("http://www.google.com", "myWindow", 
                "status=1, 
                 height=300, 
                 width=300, 
                 resizable=0"
        );
    }
  </script>
</head>

<body>
  <input type="button" onclick="myPopup()" value="popup" />
</body>

回答by Brian

Depends what you're trying to achieve... you could look at Modal Dialogue forms.

取决于您要实现的目标……您可以查看模态对话表单。

jQuery does this http://jqueryui.com/demos/dialog/for examples.

jQuery 执行此操作http://jqueryui.com/demos/dialog/作为示例。

回答by Bastardo

That is how I open a modalDialog

这就是我打开 modalDialog 的方式

function showModalDialog() {

        window.showModalDialog('HizmetSuresiUzatma.aspx', 
                               '', 
                               'resizable: no; 
                                scroll: No; 
                                dialogWidth:640px; 
                                dialogHeight:350px');

     }

after a button click on a page called HizmetListesi.aspx.I write the JS code on that aspx file then call it with

在一个名为HizmetListesi.aspx.I的页面上单击按钮后,我在该 aspx 文件上编写了 JS 代码,然后使用

ScriptManager.RegisterClientScriptBlock(this, this.GetType(), "hizmetYenileTahsilat", "showModalDialog()", true);

on aspx.cs file.

在 aspx.cs 文件中。

回答by SeekLoad

A GOOD working code with NO crashes.

没有崩溃的良好工作代码。

Simple and what makes this code betteris that you can use it in a JavaScript file separately and have it fairing to more then one file with the same popup size even though its different pages on popups.

简单且使这段代码更好的原因是,您可以单独在 JavaScript 文件中使用它,并使其适应多个具有相同弹出大小的文件,即使它在弹出窗口上的页面不同。

Javascript

Javascript

// Popup window code
function MyPopUp(url) {
    popupWindow = window.open(
        url,'popUpWindow','height=454,width=580,left=0,top=200,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no,status=yes')
}

HTML

HTML

<a href="JavaScript:MyPopUp('MyDirectory/Page.html');" title="My PopUp For You">My PopUp</a>

NOTE:You can also use this as onload in body for example <body onload="JavaScript:MyPopUp('MyDirectory/Page.html');">and it will aslo work on onmouseoverand others... though I do not advise this unless you want to piss off the clients visiting your page.

注意:例如,您也可以将其用作正文中的 onload <body onload="JavaScript:MyPopUp('MyDirectory/Page.html');">,它也可以用于onmouseover其他人……尽管我不建议这样做,除非您想激怒访问您页面的客户。