简体   繁体   English

Javascript-在不重用以前打开的窗口的情况下打开新窗口

[英]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。

window.open window.open

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.

相关问题 我可以使用什么JavaScript代码在新窗口(而不是以前打开的窗口)中打开 - What JavaScript code can I use to open in a new window, and not the window I previously opened 在chrome中的新选项卡中查找以前由window.open打开的窗口 - Find window previously opened by window.open in new tab in chrome 在使用javascript打开的窗口中打开新标签页 - Open a new tab in the window opened using javascript 查找以前由 window.open 打开的窗口 - Find window previously opened by window.open Javascript- 如何使 window.location 在新页面中打开选定的值? - Javascript- How to make window.location to open selected values in a new page? 在新窗口中打开图像…是否可以在浏览器中不打开图片? - Open image in new window…Is it possible without picture being opened in a browser? 如何使用window.open()专注于先前打开的窗口 - How to focus on a previously opened window using window.open() javascript- window.open在safari中和chrome在正文中? - javascript- window.open in safari and chrome in body? 是否可以扩展使用window.open打开的新窗口的DOM,而无需在新窗口中加载prototypeJS? - Is it possible to extend the DOM of a new window opened using window.open without loading prototypeJS in the new window? 有没有办法跟踪使用Javascript从哪个window.name打开新窗口(在新选项卡中打开)? - Is there a way to track from which window.name a new window was opened (open in a new tab) with Javascript?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM