/    Sign up×
Community /Pin to ProfileBookmark

[RESOLVED] JavaScript Across Browser Instances

I haven’t found any useful information searching around, and I suspect that what I want to do is not possible, so this is somewhat of a last resort.

The issue that I’m having deals with multiple browser windows being opened and sharing session information, which is causing some issues in our system with session data being corrupted. I realize that there are ways to handle this in the session/querystring, but that is not an easy fix due to the complexity of our application and the many entry points. Besides that, we’re in the process of refactoring and migrating our system (a process that will take years) so once the new system is complete this will no longer be a problem. For now though, I need a simple fix if at all possible.

So, the question is is there a way to detect, via JavaScript, if another instance of a browser window is already opened and browsing a particular domain WITHOUT having used window.open?

For example, if a user is browsing our site and has a valid session established, then they open another browser window/tab (same browser) and use the same session, can I use JavaScript to detect that and disallow it (via redirect to error page, or whatever)?

Just to hammer the point home, let’s say the user is at the following URL:

[url]http://www.site.com/page.htm?value=12345&info=369-425-6666[/url]

The user then copies that URL and launches a new browser window and copies/pastes that URL, which results in 2 instances of the same session.

Can I somehow detect that? Thanks in advance.

to post a comment
JavaScript

3 Comments(s)

Copy linkTweet thisAlerts:
@A1ien51May 20.2009 — You can not do it.

Eric
Copy linkTweet thisAlerts:
@semi-sentientauthorMay 20.2009 — That's what I figured. Thanks.
Copy linkTweet thisAlerts:
@rnd_meMay 21.2009 — actually you can.

just set a cookie to window.location.href.

since all pages in a domain can share cookies, you can simply check the cookie value when the page loads. if it's the same as the url, then bingo, the user in your scenario would be "caught".

of course, saving an actually token or identifier from the session would be even better than the URL, but might require a tiny bit of server-side code.

perhaps your page already has a session Id cookie or hidden form value, or something else that is unique to the session.

just setCookie the "uniqiest" thing you can find and compare the live value to the getCookie version onload.

does that make sense?
×

Success!

Help @semi-sentient spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...