【问题标题】:DHTML modal window, close on background clickDHTML 模态窗口,在背景点击时关闭
【发布时间】:2013-06-21 15:01:34
【问题描述】:

我正在使用此处找到的 dhtml 窗口小部件脚本:

http://www.dynamicdrive.com/dynamicindex8/dhtmlwindow/index.htm

我希望用户能够在单击背景时关闭 dhtml 弹出窗口。目前它仅在单击关闭按钮时有效。如何将其添加到此脚本中?

【问题讨论】:

  • 添加一个 div 元素,拉伸整个视口宽度和高度并位于窗口后面,然后添加一个 onclick 侦听器并调用关闭按钮调用的方法。如果遇到麻烦,请发布您的代码...
  • 对不起,我是新手。我发布了代码的链接。我正在使用窗口 3 选项。 JS文件可以查看。
  • 如何使用这些函数 t.hide=function(){dhtmlwindow.hide(this)} //隐藏dhtml窗口的公共函数 t.close=function(){dhtmlwindow.close(this )} //用于关闭 dhtml 窗口的公共函数(也清空 DHTML 窗口内容)

标签: javascript popup dhtml


【解决方案1】:

这不是主题所说的“dhtmlmodal”。这是用于“dhtmlwindow”的。有区别,因为“dhtmlmodal”甚至似乎没有 .close() 事件,只有 .hide()

【讨论】:

    【解决方案2】:

    那个小部件现在已经很老了(超过 6 年),毫无疑问有许多更新、更好的替代品,但这不是重点。

    您链接到的页面上的文档详细说明了如何创建弹出窗口,以及如何访问对弹出窗口起作用的功能。复制如下供参考:

    Create links that manipulate an opened window in various ways when clicked on
    
    <script type="text/javascript">
    // this function invocation generates the popup with your specific parameters
    // the variable name you assign (googlewin) is used to interact with the popup later
    var googlewin=dhtmlwindow.open("googlebox", "iframe", "http://google.com", "Google Web site", "width=700px,height=450px,resize=1,scrolling=1,center=1", "recal")
    </script>
    
    <!-- this is an example link that will call the close method on the googlewin object
    this is the bit you need to apply to whatever it is that you want the visitor to be able to click on to close the popup -->
    <a href="#" onClick="googlewin.close(); return false">Close Window</a>
    

    请记住,您使用的小部件会创建一个弹出窗口,而不是真正的模式。如果您要使用模态(灯箱),则每当访问者单击主模态内容区域之外的任何位置时,您都会内置关闭功能。

    【讨论】:

    • 是的,我知道如何创建它。我在问是否可以添加在单击此弹出窗口外部时关闭此弹出窗口的功能,例如灯箱图像窗口。目前它仅适用于弹出窗口中的链接。
    • 而且它不是弹出窗口,它是浏览器窗口中的模式。
    猜你喜欢
    • 1970-01-01
    • 2015-04-30
    • 2021-02-12
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2017-10-19
    • 1970-01-01
    相关资源
    最近更新 更多