I have a situation where I am opening a user-initiated popup window on my site that points to another site. Users shouldn't be accessing this page directly, and should only go to it under normal conditions if the site opens the popup window.
mysite.com -> mysite.myothersite.com
I noticed that the popup window page appears in history, and worse, appears in the address bar autocomplete suggestions.
This popup window is supposed to perform a one-time utility operation so it isn't useful for the user to have this in their history or autocomplete suggestions. However, users are accessing this popup directly (assuming by accident).
While I can't prevent anyone from doing this, i'm wondering if it's possible to have that page not record itself in the browsers history. It's messing with my analytics.
You might want to look at the history.replaceState functionality provided by the history API.
If the pop-up is served at the same location, simply do history.replaceState({}, 'mypage', '/my-page-address') in the JavaScript of the popup window. This way, it replaces the myothersite history entry with the mypage history entry, and instead of using mypage you can use the title and address of the original page.
This is where state comes into play. Upon requesting the popup, place some indicator that allows the popup to open and then when the user requests it, clear that indicator. This type of information is usually done via backend session state, but can also be done completely via front end, but with with a reliability hit.
Related
I have a page with a few links.
Each link opens in a new tab.
The next time I click a given link, I want it to recall the same tab where it was previously opened.
Is it possible? How?
All pages come from the same domain.
I've seen this answer:
Check if my website is open in another tab
It seems possible to store the URIs in localStorage, for repetitions detection.
I think this technique will allow me to detect repetitions, but I can't figure out how to aim at the specific tab (activate it, bring it to the front).
I don't control the server, need to implement it in the client (via Tampermonkey).
For the curious, I work a lot with BitBucket issues.
The page with the links is the issues listing, the other pages are the individual issues.
I want to be protected from opening the same issue twice, update both versions, and have a data loss.
Additionally, each page can have two different URIs, one for viewing and the other for editing. But I think I can solve it with JS.
Recalling a Browser Tab by Name
You can first specify a name for each tab you create, by using window.open():
let newWindow = window.open(newUrl, newWindowName);
or by using target attribute in an anchor tag:
Make New Window
If you then call window.open with the name of an existing tab, that will use the existing tab. If the window by that name doesn't exist, window.open will create a new window (or tab).
MDN web docs page for Window.open
Bringing Window to the Front
Using window.open() alone may not be enough to bring the window to the front. That may be possible with a different function, window.focus(), which issues a request to bring the window to the front. Combining the two:
window.open(myUrl, myWindowName).focus();
Caution: A browser's user preference setting may still prevent focus() from bringing the window to the front, so this is not guaranteed to work. From MDN web docs:
It may fail due to user settings and the window isn't guaranteed to be frontmost before this method returns.
You can get the previous page's URL with the following:
let prevURL = document.referrer;
You can get the URLs from all open tabs with the windows.getAll() function.
From this answer - You cannot programmatically focus the browser to a specific tab due to security concerns. Consider updating the title to notify the user with document.title = {{new title}}
I am working on a client site where the client has requested that there be a button (basic a link) that links to another page like google, in case an abusive significant other busts into the room while a woman is reading about how to get assistance. The tricky part is that I am trying to figure out to link to a page that will open int he same windows, but no let you go back to the site by clicking the browser's back button, or show up in "history". I have built a lot of website and never heard of this being possible without the use of a custom browser extension or something.
My question is ..
Is there a way to do this? Possible some JS magic? Just wondering
You're looking for location.replace().
<button onclick='location.replace("https://www.google.com");'>Click to close</button>
Instead of creating a new entry in browser history, it replaces the current one.
Note: Unfortunately, it's blocked by [SO]. But just try it in your app. It does work.
Second note: If you combine this with initially opening the to be hidden page in a new tab (target="_blank") => no history.
However, the best method and advice for such cases is browsing in incognito: Ctrl+Shift+N. Once closed, it's gone, with all history in the session. Pressing Ctrl+Shift+T in a new browser window won't bring the formerly opened tabs back.
IMHO, this technique should be clearly detailed in the "Precautions" section of your client's website, also advising on having another "normal" browsing session opened in a background browser window, with a few neutral tabs open on subjects that wouldn't raise any suspicions: cooking recipes, things for children, cosmetics, etc...
I am not sure about your question.
But on click you can open Iframe
<iframe src="www.google.com" style="border:none;"></iframe>
I'm new to chrome extension.
I need to have data created when working with the popup, available after closing and re-opening it.
Here're some more details about my specific problem:
whenever my chrome extension popup is opened a script runs. in the popup there's an option to click a button which will add an item to an array, which is used in order to display this list of items in another tab in this popup. However, since every time the popup is opened the code runs all over again, the array is emptied the moment the popup opens again, and obviously when the browser or the OS is restarted. I need this array to stay consistent through opening and closing of the OS, the browser and the popup itself. Any ideas?
btw - managing it from a background page is not good enough since the moment the os is restarted the background page session stops and the data is lost
When a popup is closed, its HTML document is completely unloaded; you need to restore state when your popup loads every time it's opened. No way around that.
As you mention, it's possible to persist state information in the background page while the browser is running. But it's still temporary storage; you need to use persistent storage to save whatever state you need to save.
The most obvious (and recommended) choice is chrome.storage API, specifically designed for this purpose. You can also use Web APIs such as localStorage or IndexedDB if you like.
Most resources suggest using onclick handler with trackEvent() for tracking outgoing links. BUT this way does not work with all navigation methods! It won’t work if you click with middle button (except Chrome) or control-click (except Chrome and FF) to open new tab, if you right-click and select new tab or window from context menu or if you drag link to another tab. Is such cases onclick is simply not called. You can check it with very simple link:
GO
Putting JavaScript in href attribute breaks the link in all cases when new tab or window is opened.
Putting onclick in span that looks like a link, will not allow users to decide if they want to open in new tab or not.
Finally, going through a redirect page, which tracks outgoing event, causes problems with back navigation – when users try to go back, they get back to the redirect page and then JS again redirects to the destination page. They need to click back twice … quickly.
Is there a better way, which would be both accurate and user friendly?
Context menu can't be detected by using JS. So if you want to catch that you need to use the redirect method. To fix the back button problem, redirect using location.replace to remove the tracking page from the back-button history.
I don't know any details about Google Analytics. In general, to track users' external navigation:
<a ping> is made for this purpose. If ping is not available, fall back to changing the links to go through a redirect page. Use a 302 redirect to prevent it from showing up in history; if you can't, try javascript:window.location.replace().
My webapp has a CLIENT_CERT based JAAS authentication. I am using IE7.
When I click on logout, it takes me to my home page. Now clicking on the back button, the user should remain on the same page, which I acheived using history.forward() javascript. But the certificate dialog comes up since the previous page was secured.
How can I avoid the certificate dialog from not coming and also remain on the non-secure home page when user clicks on back button after logging out.
The only way to disable the back button within a window is to use location.replace() for every single interaction, which you cannot do if you need to submit any forms unless you target them to a hidden iframe and then do a location.replace() in reaction to the iframe's onload event once the form is submitted. This is really nasty and complicates everything.
The other technique to avoid users going back through pages (some online banking sites do it this way) is to launch the secure section in a new window, and have logout close it (you can force a close in IE with window.opener = null; before window.close();.