javascript window.open 不在同一个会话中打开
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/6580550/
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
window.open doesn't open in same session
提问by Karthik Murugan
I'm using the below anchor tag on a JSP page to open another page from the same application, but the new window is not opened in the same session and instead it redirects to the login page of my application. Any clues why?
我在 JSP 页面上使用以下锚标记从同一应用程序打开另一个页面,但新窗口未在同一会话中打开,而是重定向到我的应用程序的登录页面。任何线索为什么?
<a href="#" onclick="window.open('/path_to_same_page', '_blank',
'toolbar=0,status=0,resizable=1'); return false;">Click here...</a>
采纳答案by Karthik Murugan
Reason behind this behaviour is, the parent page is hosted on a IE web browser control embedded in our windows application. When it creates a new window (either using window.open or target="_blank"), the new window is owned by iexplore.exe process and doesn't inherit the session cookies from the parent IE window, which is owned by our application process. There is no generic solution to this problem. In our case, we used some kind of Single Sign On to share the session context between two window instances.
这种行为背后的原因是,父页面托管在嵌入在我们的 Windows 应用程序中的 IE Web 浏览器控件上。当它创建一个新窗口时(使用 window.open 或 target="_blank"),新窗口由 iexplore.exe 进程拥有,并且不会从我们的应用程序拥有的父 IE 窗口继承会话 cookie过程。这个问题没有通用的解决方案。在我们的例子中,我们使用某种单点登录在两个窗口实例之间共享会话上下文。
回答by Simon Lieschke
You stated in your answer that
你在回答中说
the parent page is hosted on a IE web browser control embedded in our windows application
父页面托管在嵌入在我们的 Windows 应用程序中的 IE Web 浏览器控件上
There actually is a solution to this problem. Your application needs to handle the NewWindow2
event in order to maintain the session across windows.
这个问题其实是有办法解决的。您的应用程序需要处理该NewWindow2
事件以维持跨窗口的会话。
Refer to the following MSDN resources for details on this:
有关这方面的详细信息,请参阅以下 MSDN 资源:
- How to use the WebBrowser control NewWindow2 event in Visual C#
- How to use the WebBrowser control NewWindow2 event in Visual Basic .NET
- How To Use the WebBrowser Control NewWindow2 Event(for Visual Basic 5.0 and Visual C++ 5.0)
- 如何在 Visual C# 中使用 WebBrowser 控件 NewWindow2 事件
- 如何在 Visual Basic .NET 中使用 WebBrowser 控件 NewWindow2 事件
- 如何使用 WebBrowser 控件 NewWindow2 事件(对于 Visual Basic 5.0 和 Visual C++ 5.0)
回答by Shadow Wizard is Ear For You
Try this workaround, not sure it will help but worth a shot:
试试这个解决方法,不确定它会有所帮助但值得一试:
<a href="/path_to_same_page" target="mywindow" onclick="window.open('/path_to_same_page', 'mywindow', 'toolbar=0,status=0,resizable=1');">Click here...</a>
By having this, the window won't get opened by script initially, but rather by the target
attribute.
有了这个,窗口最初不会被脚本打开,而是被target
属性打开。
回答by Hearaman
first encode that url with encodeURL(""); and then add in javascript file
首先使用 encodeURL("") 对该 url 进行编码;然后在javascript文件中添加