`
lichangwei
  • 浏览: 74946 次
  • 性别: Icon_minigender_1
  • 来自: 苏州
社区版块
存档分类
最新评论

Create multiple popup windows and keep a reference

阅读更多
Transshipment: http://www.sitepoint.com/forums/showthread.php?t=45412

I am trying to write a script that will allow a window to create multiple popup windows and keep a reference to each popup window by populating an array. Then at anytime I want to access one of the child windows I can by finding it in the array and using that window object.

To make sure I can do this I made this script below which opens a page with some open window links and close window links. I should be able to open both windows and close both windows using the appropriate window objects from the array.


<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">

<html>
<head>
<title>Untitled</title>


<script>
<!--

/*----------------------------------------------
In this script, I can create as many new windows as I want
by just creating a link on the page that executes the 
openWindow(winURL, winName, winFeatures) function. This in turn
creates a custom object that I defined by calling the popUpWindow
constuctor. 

My custom popUpWindow object has 2 properties: 
1) unique name of window 
2) the actual window object itself. 

Then I put that new custom object into an array 
object (newWindowsArray) which is Global in scope which allows
me to refer to it anywhere in the code.

Doing this let's me dynamically create new windows but still have 
a handle on each window object allowing me to call any of its
methods. For example, I wouldn't be able to close the new window
from the parent window without this object handle. 

These scripts are generic which allows me to put it inside a larger 
script library file for including in any page that needs 
this type of script.
----------------------------------------------*/

//create a global array object to hold custom poppUpWindow objects
var newWindowsArray = new Array();

function popUpWindow (winName, windowObject){
	this.name = winName;
	this.winObject = windowObject;
}

function openWindow(winURL, winName, winFeatures){
	var newWindow = window.open(winURL, winName, winFeatures);
	var win = new popUpWindow(winName, newWindow);
	newWindowsArray[newWindowsArray.length] = win;
alert('newWindowsArray.length'+ newWindowsArray.length);
	newWindow.focus();
}

function closeWindowByName(winName){
	for(i=0; i<newWindowsArray.length; i++){
		if(newWindowsArray[i].name==winName){
			newWindowsArray[i].winObject.close();
			break;
		}
	}
}

//-->
</script>
</head>

<body>

<a href="javascript:openWindow('http://www.iteye.com', 'window1', 'height=300,width=300')">open window1</a>
<a href="javascript:openWindow('http://www.iteye.com', 'window2', 'height=300,width=300')">open window2</a>
<br><br>
<a href="javascript:closeWindowByName('window1')">close window1</a>
<a href="javascript:closeWindowByName('window2')">close window2</a>


</body>
</html>


Note: Cannot Add windows object into a array directly. You will get a "Access is denied" in IE.
function openWindow(winURL, winName, winFeatures)
{
newWindow = window.open(winURL, winName, winFeatures);
newWindowsArray[newWindowsArray.length] = newWindow;
}
分享到:
评论

相关推荐

    仿windows系统提示框,popup提示框

    "仿Windows系统提示框,popup提示框"是UI设计中的一个重要元素,它模仿了微软Windows操作系统中常见的警告、信息或询问对话框,以提供给用户即时反馈。这样的提示框通常具有鲜明的黄色背景,以吸引用户的注意力,...

    intellitamper

    Tired of closing and jumping between multiple popup windows, thousands of stupid links on a single page, sites without real content and only ads, etc... ? IntelliTamper is a small and easy-to-use ...

    Popup例子 实现弹出窗口的关闭

    首先,Popup是Windows Presentation Foundation (WPF)和Windows Phone应用程序中常用的一种UI元素,它可以用来显示临时或辅助信息,不打断用户的主线操作。在WP界面上,Popup通常用于显示警告、设置或者一些简短的...

    as97Popup.ocx

    ActiveX技术是由微软公司推出的,主要用于Windows平台上的Web浏览器和应用程序,允许开发者创建交互式和动态的内容。ocx是OLE(Object Linking and Embedding)控件交换格式,这些控件可以被网页或者应用程序调用来...

    WPF:带阴影、带箭头的Popup提示框

    在Windows Presentation Foundation (WPF) 中,Popup是一个非常实用的控件,用于创建浮动的、非模态的用户界面元素,它可以显示在主窗口或其他UI元素之上。在本项目"PopupSamples.7z"中,我们可以期待看到一系列的...

    regsvr32.exe as97Popup.ocx无法注册问题需要的控件包

    `as97Popup.ocx`是一种ActiveX控件,ActiveX是Microsoft开发的一种技术,允许在Web浏览器或其他Windows应用程序中嵌入和执行小应用程序或组件。这些控件可以提供额外的功能,如播放视频、运行交互式工具等。然而,...

    popup 弹出框 js

    在网页设计和开发中,`popup`弹出框是一种常见的用户交互元素,它可以在用户进行特定操作或需要显示额外信息时出现。`popup`通常用于登录注册、消息提示、广告展示、确认操作等场景。本篇文章将深入探讨`popup`弹出...

    Popup

    Popup在IT领域通常指的是弹出窗口或提示框,它是一种用户界面元素,用于显示临时信息、警告、确认或请求用户输入。在网页设计、应用程序开发和操作系统交互中,Popup经常被使用,为用户提供额外的交互可能性。 在...

    Silverlight Popup

    在“Silverlight Popup Windows Demo”项目中,我们可以看到如何使用Popup来实现弹出窗和模式窗。模式窗是一种特殊的弹出窗,用户必须关闭该窗体后才能继续与主界面交互,常用于警告、确认或输入信息的场景。通过...

    wpf使用Popup封装数据筛选框,wpf使用Popup封装数据筛选框

    在Windows Presentation Foundation (WPF) 中,`Popup`控件是一个非常实用的组件,它能够创建浮动式的用户界面元素,可以在屏幕上的任意位置显示。在数据处理和展示中,我们经常需要实现数据筛选功能,以帮助用户...

    关于popup的使用

    Popup在Web开发中通常指的是弹出窗口或者对话框,它是一种常见的用户交互方式,用于显示额外的信息、警告、确认操作或者其他交互元素。标题"关于popup的使用"表明我们将讨论如何在网页中应用popup,而描述中提到...

    Easily_create_pretty_popup_messages_(modals

    Easily_create_pretty_popup_messages_(modals)_in_Sh_shinyalert

    popup.js及详细示例

    在JavaScript的世界里,`popup.js`通常用于创建自定义的弹出框或对话框,它是一种用户界面元素,用于提供额外的信息或者与用户进行交互。`popup.js`文件是实现这种功能的脚本,它可能包含了创建、显示、隐藏以及处理...

    Change from child window to popup window (and back)(277KB)

    标题为“Change from child window to popup window (and back)”的主题涉及到Windows API中的两种主要窗口类型:子窗口(Child Window)和弹出窗口(Popup Window)。理解这两种窗口类型及其转换方法对于Windows...

    C#自定义控件--Popup窗口提醒完整源码

    - Popup窗口在WPF中是System.Windows.Controls.Popup类的实例,而在Windows Forms中则没有直接对应的控件,但可以通过自定义控件实现类似的功能。 - Popup窗口的位置和大小可以灵活调整,通常会关联到另一个控件,...

    popup.js文件

    `popup.js`文件通常是在Web应用程序中用于实现弹窗功能的JavaScript脚本。在这个场景下,`popup.js`可能是一个独立的JavaScript模块,负责处理与弹窗相关的一切交互和逻辑。 弹窗在网页设计中扮演着重要的角色,...

    Teebo PopupNotify (Office and MSN Style Popup Alert Control for VB )

    PopupNotify is an ActiveX control that lets your applications... Popup Notifications gracefully fade in and slide up above the taskbar tray, and can be set to disappear by themselves after a few seconds.

    很好用的popup控件

    Popup控件在网页开发中是一种常见的交互元素,用于弹出窗口或者提示信息,提供额外的交互体验。在本例中,我们讨论的是一个基于jQuery的高效popup控件,它能够展示固定内容、加载远程数据以及嵌入iframe。下面将详细...

    popup.js下载

    popup.js下载

    Popup And Insert SubPanal.zip

    在LabVIEW编程环境中,"Popup And Insert SubPanel.zip" 是一个包含了一系列用于动态创建和管理子面板(SubPanel)的示例项目。这个压缩包主要关注如何在运行时通过编程方式打开子面板,并以弹出窗口或嵌入到现有VI...

Global site tag (gtag.js) - Google Analytics