[英]Javascript- Open New Window Without Reusing Previously Opened One
So my problem is I have a button on my original page that should open a new window so the user can create a new object. 所以我的问题是我在原始页面上有一个按钮,该按钮应该打开一个新窗口,以便用户可以创建一个新对象。 This works fine the first time I press the button.
第一次按此按钮时,此方法工作正常。 However, if I want to create another object at the same time and press the create new object on my original page, instead of creating another new window, the site just opens the new create object page on the same window of the first new object I was trying to create.
但是,如果我要同时创建另一个对象,然后在原始页面上按创建新对象,而不是创建另一个新窗口,则该站点只是在我第一个新对象的同一窗口上打开新的创建对象页面。试图创造。 Obviously this results in all the information I originally typed to create a new object being lost.
显然,这会导致我最初键入以创建新对象的所有信息丢失。
Here is the onClick that calls my openPopWindow function which opens the window. 这是调用我的openPopWindow函数的onClick,它将打开窗口。
onClick="openPopupWindow('<% =NEWOBJECT_URL %>', 0);"
Here is the openPopWindow function 这是openPopWindow函数
function openPopupWindow(strPage, TicketId){
var winTop = 10;
var winLeft = Math.round(screen.width / 2) - 800/2;
var POPUP_FEATURES = "scrollbars=no,resizable=yes,toolbars=no,status=no,height=650,width=800";
POPUP_FEATURES += ",top=" + winTop + ",left=" + winLeft;
var POPUP_NAME = "NewViewWindow"
var POPUP_FNAME = strPage;
var PopupURL, URLParams;
var theWindow
PopupURL = POPUP_FNAME;
theWindow = window.open(PopupURL, POPUP_NAME, POPUP_FEATURES);
theWindow.focus();
return theWindow;
}
So is there a way so that a new window can always be opened instead of reusing the same opened page? 那么有没有一种方法可以始终打开一个新窗口,而不用重复使用同一打开的页面? Any help is greatly appreciated!
任何帮助是极大的赞赏!
If a window with the name already exists, then strUrl is loaded into the existing window.
如果具有该名称的窗口已经存在,则将strUrl加载到现有窗口中。 In this case the return value of the method is the existing window and strWindowFeatures is ignored.
在这种情况下,该方法的返回值是现有窗口,而strWindowFeatures被忽略。 Providing an empty string for strUrl is a way to get a reference to an open window by its name without changing the window's location.
为strUrl提供空字符串是一种通过其名称获取对打开的窗口的引用而无需更改窗口位置的方法。 To open a new window on every call of window.open(), use the special value _blank for strWindowName.
要在每次调用window.open()时打开一个新窗口,请对strWindowName使用特殊值_blank。
var POPUP_NAME = "_blank"
also note from the docs that the window name is not the title. 从文档中还请注意,窗口名称不是标题。 To set the title you would do
要设置标题,您将要做
theWindow.document.title = "NewViewWindow"
Instead of a fixed POPUP_NAME
you could use a random string or better just use the current timestamp as Date.now()
除了使用固定的
POPUP_NAME
您还可以使用随机字符串,或者最好使用当前时间戳记作为Date.now()
So it would look something like 所以看起来像
theWindow = window.open(PopupURL, `win${ Date.now() }`, POPUP_FEATURES);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.