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

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.

Related

Open new window (tab) and keep data

This problem is similar to Angular uiRouter open state in new window or tab with stateParams, but the only answer does not seem to work.
I'm displaying a grid where users can select up to 1000 rows. There's a print button which is supposed to open a new tab in the browser with these rows in a printable format.
In my controller, I'm setting these rows (articles) in a service, then I open the new window:
articlesService.setArticles(selected);
$window.open($state.href('newwindow', {}, {absolute: true}), '_blank');
This does open the new tab, however, the data in my service is lost. I'm really supposed to use a new tab. I was thinking about storing the data in a cookie, but as I could have more than 1000 rows, that's not really an option. I'm also not passing anything in the url, as the user can select whatever he wants.
Is there any way to achieve this functionality?
You need to store data using ngStorage:
http://ngmodules.org/modules/ngStorage
This module enables you to store data in the browser and use it from different tabs and even across sessions; it provides access to the browser's Local Storage in proper Angular fashion. Local storage is a persistent (key, value) tuple storage mechanism.

How to reload another tab in 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

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

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

How to force clicking on "Refresh" link button after saving some data into DB , by javascript?

I'm completely newbie in JavaScript. Now my problem is:
I have a page (Default.aspx). The page has a link button "Refresh" (lbtnRefresh) and another linkbutton (lbtnSave) which saves some data users has entered into DB.
I want the page be refreshed after saving data into DB, by using javascript.
Is that possible or not?
Thank you
Try using the following function:
window.location.reload(true);
The true argument will force the browser to bypass the cache and reload from the server.
You can simply do it by changing the current window location
window.location = 'http://www.stackoverflow.com/?timestamp=6546546416';
To avoid cache, you can add a timestamp to the url.

Categories