How to reload another tab in javascript? - javascript

I work on an admin-side database and we want the admin to open clients' account. Since we use session variables, we want to restrain the admin to one client account at a time.
So here's the plan, when selecting a first client, the client-side page loads in a new tab. If the admin selects a new client, the new tab reloads for this client.
For now, I tried using a global variable named clientWindow and when a client is selected, I do
clientWindow = window.open('site.html?playerid='+playerid, '_blank');
clientWindow.focus();
But it still opens a new tab. Perhaps I'd need a name to put instead of _blank!
Thanks for you help.

Give the window an actual name, rather than _blank. Then it becomes part of the DOM, and you can access it directly. Including refreshing it

Related

How to use window.open with state data (React)

I'm trying to replace history.push to window.open (to of course open in a new tab). I tried to use query params to access my state's data to be fetched in the new tab.
window.open(`/${db}/endpoint?var1=${link.var1}&var2=${link.var2}`)
Anyone has a tip for this problem? Thank you!
If you use window.open then the script will be loaded from scratch in a new tab (will not be connected to the previous tab in anyway), so either you have to load data from local storage if you want to share some data between sessions or tabs.

Preventing user from opening multiple tabs for the application

In my application, it should not allow the user to open the application in multiple tabs for same browser. I need to implement this for some security purpose. How can i implement this?
Generate a session ID on server side every time a user opens your application. This session ID should be specific to the browser, IP, MAC and any data you receive as part of the initial request. For every subsequent request, validate the session ID.
Any link in your application should send a POST request, best would be submitting a form, and not a GET request so it does not open in another tab.
If a user intentionally opens your application in another tab, since you would know you already have a session ID generated for the requested data, invalidate the previously generated session ID, log the user out, and destroy the session.
A simpler way is to subscribe to localStorage notification and then update a node. Since events are not sent to the updating tab, it will only affect previously opened tabs.
Example in jquery:
$(window).on("storage", function(ev) {
if (ev.originalEvent.key == "tabsync") {
window.close(); // will probably not work if the user opened the tab
window.location = "/onetabonlyplease";
}
});
localStorage.setItem("tabsync", Date.now());

Direct to URL Page on open VBScript

This should be simple, I want to know how to open a new page in the same window using VBScript?
steps:
when open page go to database
retrieve the records you need
Build URL where you want user to be redirected
Using response.redirect send user to desired page. It will open page in the same window.
You also can use JavaScript set.location to same url with basically same effect.
Depends on how heavy data is and how well your data retrieval methods are it could be so fast that user nor even realizes that he was not on the same page, however if browser set to alert user on redirect that would be a different story.
If you are trying to redirect your page to a new page you should be able to use a redirect
really simple example vbscript:
Dim URL
URL = "mywebpage.com/newpage.asp"
Response.Redirect (URL)
this page has a few other examples:
http://msdn.microsoft.com/en-us/library/ms524309%28v=vs.90%29.aspx

FB.init keeps adding fbsr_* cookies

I'd like to use Facebook Login/Connect to authenticate users on my website. The system consists of two things: 1) client side use of the FB JS SDK to auth the user and to set a (fbsr_) cookie, 2) retrieve this cookie on the server side and make a request against FB backend to get their email, that I'll use as an ID. (I'll use G+ login etc as well so email looks like a good common denominator.)
I pretty much copied what's here: https://developers.facebook.com/docs/facebook-login/login-flow-for-web/
The problem is, every time I refresh the page, I see that a new fbsr_${my_app_id} cookie is created. After 10 reloads in a row, I end up with 10 cookies that have the same name (and same domain) and different content. In other words, it looks like FB.init() always creates a new cookie and doesn't re-use the previous one (which becomes invalid). My observation is based on what I see in the "Cookies" window of Firefox in this case.
Am I doing something wrong? What can I do so the FB API reuses the previous cookie and doesn't create a myriad of cookies with the same name on my domain?
Thanks!

Is it posible to open a window then close the window in javascript?

I am not sure how to get by this one. I am using openId with the dotnetopenauth library.
I have some predefined provider that when clicked does a jquery post to the server and does a request to the provider.
I get the url back from provider and I do window.open(....) and open it as a new window with a predefined height and width.
Now they log in and do all that great stuff. Now the provider sends me their information to a controller method that I specified.
Now after I authenticate them I want to go to a new page. However I want to the page to open in the main window and no the window that I opened with window.open(). I want that closed and gone.
I can't get it to work. It will just start using that window.open() window to load all the pages in and I don't want that.
So I no clue what to do.
You just need to keep a reference to the first window around:
var oauthWindow = window.open(....);
later:
oauthWindow.close();
It's a complicated piece of work to get right, to be sure.
A couple of good examples are:
NerdDinner (source)
DotNetOpenAuth ASP.NET MVC 2 project template

Categories