I have a Javascript Expand/collapse Menu . When open New Window a session cookie is created to maintain the states of the menu(i.e, Expanded or Collapse).
1.If we open some node of menu.It maitain their states in cookie.
2.But when we open new browser window, then no new session made ,it get the pervious session,due to this, Menu still showes expanded.
3.But if we close all the browser then it is working fine,it creates new session in this case.
I need to open a second browser window or tab, but it must have a different SessionID. Opening the new browser window from an ASP.NET page is easy, but then it shares the same cookie and thus SessionID with the original.
How can I do this?
Thanks for help,
Jaydeep
As per my understanding you should not use session id for the logic of displaying menus in your form. Instead of this you can just use hidden field value or querystring value.
I need to open a second browser window or tab, but it must have a different SessionID
Sorry but this is impossible to achieve. That's how browsers work and you have no control over this behavior. Take for example gmail: you log into your account and then open another browser tab/window and you will still be logged in because cookies are shared between tabs/windows.
So you should use some other storage mechanism like url ids or hidden fields, and not cookies.
To get possibility to use different sessions in different browser tabs, You can use cookieless sessions. You can read about in MSDN.
Related
Working with Edge browser, I would like to open a new window and/or tab without keeping current window session.
I have it working for Firefox like this:
Open new window -> window.open('mySiteURL', '_blank', 'status=no,noopener=yes');
Open new tab -> window.open('mySiteURL', '_blank', 'noopener=yes');
i would like to achieve the same for Edge browser.
I would create a buffer of new drivers for every new window or tab you want to open.
When you'll have used JS window.open() function,
just do driverOfOldWindow.close() and it'll close the previous window.
Don't use driverOfOldWindow.quit() cause it'll close all the browser windows, this is not what you may want to do since your WebDriver could have opened other windows that you may want to be still working.
To manage tabs just use the getAllWindowHandles() function and call close() method on the ones you want to close too.
Look here
IE may create multiple content processes for content in different windows and tabs.
If your application 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".
(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).
Opening a new window create a new session
Is there a reliable way to know if an other instance of the same page is already opened in the browser?
I’ve tried setting up a variable in local storage at load and unload but mobile browsers do not always send the unload event..
The context of JavaScript code is per opened page (called window). Therefore, there is no reliable way to track open pages unless you open a WebSocket connection to the server and check the number of open pages by associating a unique identifier to each of them and prevent opening multiple pages. If you want to take this approach, search for a WebSocket implementation of your server-side application.
I am using sessionStorage to ensure an action only happens once per session. However, if a user opens a new window - the sessionStorage is not carried over to the new window, and the action is executed again. See my code below:
if sessionStorage.alreadyTracked != "1"
sessionStorage.alreadyTracked = "1"
...
Is there an easy way to do this that applies to all tabs? Maybe I need to use a cookie?
As far as html5 storage goes i would go for localStorage in your case.
See below for the differences.
Session Storage:
Values persist only as long as the window or tab in which they
stored.
Values are only visible within the window or tab that
created them.
Local Storage:
Values persist window and browser lifetimes.
Values are shared across every window or tab running at the same origin.
Read more here
You probably want to switch to localStorage as sessionStorage is bound to individual tabs and localStorage is not.
If you're OK with targetting only FF/Chrome you might also want to take a look at the Broadcast Channel API
The Broadcast Channel API allows simple communication between browsing contexts (that is windows, tabs, frames, or iframes) with the same origin (usually pages from the same site).
Using Web Messaging (postMessage), it's easy to send messages between windows including iframes and popup windows opened through Javascript. However, is it possible for two windows opened individually by the user to find each other and communicate?
As an example, if the user opens www.example.com/app.html in the browser, then the same page in another tab/windows of the same browser, I want the second window to know that it should act as a "child" of the first one and exchange a stream of events via postMessage. How do I detect the presence of another open window and how to I get a handle to it that I can use with postMessage?
i don't know if it's possible with postMessage.
but, it should be possible with localStorage or sessionStorage (which lives in the session scope).
using this approach you can write a value in one window/tab, and read it in the other window/tab, of course assuming that it's all on the same domain.
see more here: http://php-html.net/tutorials/html5-local-storage-guide/
hope that helps.
Is there a way to set a browser session cookie in Javascript, so that only that browser instance can see that cookie. For example, if I set a cookie via Javascript in one instance of Firefox, and then invoke a second instance of Firefox (Ctrl-N or launching firefox.exe again), I do not want that second instance to be able see this cookie.
How would I go about this? Thank you.
You can't. Different browser windows are just different windows to the same instance. Launching Firefox again just spots the running instance and opens a new window in it.
(There are some command line options which might open a new instance (in particular the one to load a different user profile), but that is entirely a client issue and any JS is by the by).