When my webpage query is executing long, the website looks like it froze to an average user. Therefore, I was hoping to add a button to cancel the query and the load.
To do currently, I would have to F12 (in Chrome), go to Application with Clear Storage, and then click Clear site data. Is there any way to do that through code?
I tried clearing cookies, local storage, session storage. Doesn't seem to work unless I Clear site data.
Related
So, I am making a Chrome extension that connects to an external server and allows you to chat with other users of the extension. However, the way my extension is set up right now is with a start page (the initial popup), and then a button that takes you to the chatting page.
I want to figure out a way that allows the extension to stay on the chatting page after the user passed through the start page already. Moreover, I want the chat's messages to be saved as well.
I know I can do this by using Chrome.pageAction.setPopup(). However, I don't if this is the way to go about. As for the messages, I am not sure where to start, do I store them in Chrome localStorage? what are the ways I can go about doing this?
I apologize if this is a trivial question, I am new to all this.
I have an application that on load makes certain requests to backend to fetch data.
On the other hand, I have a web extension that basically modifies the behaviour of the browser's new tab so that when a user clicks new tab my application opens up. It's a productivity tool and users want this. The web extension is mostly an iframe that opens the application inside.
The problem I have is that every time a user clicks new tab, since the app starts loading in the new tab, a request to fetch the data from backend is made independently of if the user really wants to browse through the application or just navigate anywhere else with the new tab. In other words, 95% of the time the users just click new tab to browse and not to see my app. Obviously, this adds a lot of useless load to my server that I want to control.
What I do now as a temporary solution is to store the data in the localStorage, so that when a user clicks new tab, the data is loaded from the localStorage and can immediately be browsed, while I delay the fetches from backend to 12s. 12s because I figure it's enough time to click new tab, make a google query and navigate away. This reduces the load a lot, but obviously, delays the refetch of data for everyone for 12s.
Since the app can be used from multiple devices, delaying the synch for 12s is quite annoying.
Can you think of a better solution? (Obviously, I have no way to know if the users click newtab to see the app or to browse away, actually, not even they know!! so it's a tough one.)
Of course I already added a button to allow users to manually refetch on demand, but it's not a good solution UX wise.
Another way to minimize the load would be to just add the delay of the fetch to those requests coming from the web extension. But since the web extension is just an html that loads an iframe with the website, which ultimately makes the request, I'm not sure if there's a way to know if the request comes from the web extension at all. Is there?
Thanks!
I would like to know how i can prevent users from opening a new tab while he/she still open the previous browser instance?
My purpose is to prevent from overriding the data.
For example, if the users open a new tab within same application, I want to prompt the message like
"You are trying to open a new active window within same application.Please close previous window."
Is there any way to do it with php, javascript, session or cookie ?
I would go with session info in PHP I think... when a user opens a tab, add to the session what tab it is. And if it's already have loaded that tab, ask the question. The tricky part is to know when the user has stopped using your app or just idling.
You can never prevent a user from opening a new tab in their browser, but you can prevent info from your app to getting to the user. You could work with cookies also, but I see no point if it doesn't need to be remembered longer than the session.
You could also look at HTML5 web storage if you want to make the check with JavaScript instead of PHP. It will work with IE8 and above. It's kind just a key/value database.
As long as it's the same browser window, you cannot say if user opened a new tab, or just loaded the page on the same one. Even in private mode or incognio mode, tabs share sessions.
Sessions depends on cookies, where cookies can be more persistent than sessions. Same issue.
What you can do, is to prevent user to logging again while his previous session is still valid, but this will work when user opens new browser window (or different browser) and tries to log in.
As I understood it HTML5's sessionStorage is intended to last the duration of a single user session assuming a given website. This means that it should survive reloads or page-to-page navigation within the given site. I think it should even survive if you navigate off a site and then come back within the same browser tab.
In any event, I have no problem saving the information to the sessionStorage with sessionStorage.setItem('foo','bar') but as soon as I reload or go to another page on the same site I loose my session storage.
I'm using the latest Chrome on OSX (if that matters). Here's what my session storage looks like in Chrome's debugger (when it's set):
And then after a reload of the same page:
I'm tasked with coming up with a way to determine if a person has reached our site via using their back button (meaning they left our site and came back) and log them out if so.
I've come up with some options, but am wondering what other options I may be missing.
FYI, we do have a session state, so server-side we're covered for long absences, but they want an additional check on the client side.
option 1: set a cooking via onunload that expires in x seconds. On each page of our site, I check for said cookie. If it exists, I assume they came from another page on our site and do nothing. If it's not there, I assume they have been gone from our site more more than x seconds and redirect out. Con: Blackberry devices running OS5 don't support onunload.
option 2: same as #1 but instead of setting cookie onunload, we set it on every click of every link that goes to another page on our site. con: messy
option 3: check browser history on every load of every page of our site. If the previous URL is not one of ours, we log them out. Cons: browser support? It looks like previous/next history objects are now blocked in modern browsers due to security.
Option 4: Via JS, every x seconds, check for a cookie. If it's there, reset it to expire in x seconds. If it's not there, assume they've returned from somewhere else. Con: Not sure if the JS cookies would be set while that page may be in the background (app switching on an iPhone, or using a different tab in a desktop browser).
Any other options I should consider? Is there a 'proper' way to handle this? Is this just grasping at straws trying to prevent normal browser behavior?
You could keep the current page name/action/identifier in a session variable, then use a javascript onChange/load/keyup/keydown to request the current state of the user from the server. If it does not match, redirect or otherwise block them from viewing the current page.
This is a method that I've used, but it has it's downsides.... for example, onload doesn't always seem to work when the user uses the back button. OnChange, etc on certain form fields definitely works. Timers are pretty straightforward, as well, but a quick user can get input through the page regardless.
It's not that complicated... Use javascript history object
history.next gives you the complete url of the page in the forward button. A simple regex can tell if it's from your domain or not.
I just don't know if it's supported by all browsers