Javascript 打开一个新窗口创建一个新会话
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/8472407/
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
Opening a new window create a new session
提问by BenjaminB
We are upgrading a web-based software from Windows XP with Internet Explorer 6 to Windows 7 with Internet Explorer 9.
我们正在将基于 Web 的软件从带有 Internet Explorer 6 的 Windows XP 升级到带有 Internet Explorer 9 的 Windows 7。
Furthermore, a webbrowser object is used inside a WPF application.
此外,在 WPF 应用程序中使用了 webbrowser 对象。
We now have a strange behavior, when opening a window with a url (with an instruction like window.open(url)), the ASP session is "lost" and the new window works with a new from scratch session.
我们现在有一个奇怪的行为,当打开一个带有 url 的窗口(使用类似 window.open(url) 的指令)时,ASP 会话“丢失”,新窗口使用一个新的从头开始的会话。
I solved this issue by avoiding useless windows opening and instead, I modify the location of the current window. But I would like to understand why this behavior !
我通过避免打开无用的窗口解决了这个问题,而是修改了当前窗口的位置。但我想了解为什么会出现这种行为!
Do you have any clue ?
你有什么线索吗?
Thank you.
谢谢你。
回答by Pete Duncanson
This could be cause by a simple different in your domain name, if you are running on www.yoursite.com but the window points to yoursite.com then a new session will be created. A nasty one to catch so look out for it.
这可能是由于您的域名的简单不同造成的,如果您在 www.yoursite.com 上运行但窗口指向 yoursite.com,则将创建一个新会话。一个讨厌的人,所以要小心。
Additionally you might have some debug code floating around in a page somewhere, this can cause a lot of head scratching, clearing out a session variable for testing for instance. Something else to check for, long shot though but you never know.
此外,您可能会在某个页面的某个地方浮动一些调试代码,这可能会导致很多麻烦,例如清除会话变量以进行测试。还有什么要检查的,虽然远射,但你永远不知道。
回答by AnthonyWJones
Assuming your navigation all go to the same domain then another cause for this could be the switching of processes. As of IE8 the IE "chrome" and tab content were seperated into two processes. Further IE can create multiple content processes for content in different windows and tabs.
假设您的导航都转到同一个域,那么另一个原因可能是进程的切换。从 IE8 开始,IE“chrome”和标签内容被分为两个进程。此外,IE 可以为不同窗口和选项卡中的内容创建多个内容进程。
If your app is hosting a webbrowser control which then launches a full IE window, the chances are that your new URL is being requested by another process (iexpore.exe) not your apps process. As a result the request does not have access to session cookies hence the session appears "lost".
如果您的应用托管了一个 webbrowser 控件,然后该控件会启动一个完整的 IE 窗口,则可能是另一个进程 (iexpore.exe) 而不是您的应用进程请求了您的新 URL。因此,该请求无权访问会话 cookie,因此会话看起来“丢失”。
(Its worth noting that the multiple iexplore.exe process instances in the same process tree have a means of sharing session cookies with each other).
(值得注意的是,同一进程树中的多个 iexplore.exe 进程实例具有相互共享会话 cookie 的方法)。
回答by neouser99
I think you are likely having the same problems that this answeraddresses. Essentially it is probably due to Security Zone errors within IE on the specific computer you are using. As others have noted and I can reiterate, sessions are carried into other IE (6, 7, 8, 9) windows opened by javascript, as long as the domain is not changing.
我认为您可能遇到与此答案相同的问题。本质上,这可能是由于您正在使用的特定计算机上的 IE 中的安全区域错误。正如其他人所指出的,我可以重申,只要域没有改变,会话就会被带到由 javascript 打开的其他 IE(6、7、8、9)窗口中。
Good luck!
祝你好运!
回答by Gabriel Gartz
Some references to help you:
一些可以帮助您的参考资料:
When you open a new window using the javascript as default IE, create a new window, as well isn't the same session and history. If you get the last referrer from a javascript new window, it will come empty in major browsers.
当您使用 javascript 作为默认 IE 打开一个新窗口时,创建一个新窗口,以及不同的会话和历史记录。如果您从 javascript 新窗口获得最后一个引荐来源网址,它将在主要浏览器中变为空。
And you can keep your session history if your window.open function is triggered inside an anchor object:
如果 window.open 函数在锚对象内触发,则可以保留会话历史记录:
<script>
function windowOpen() { window.open("my_page.asp","_blank"); };
</script>
<a href="javascript:windowOpen();">my link</a>