I'm sure this isn't possible but I'll ask anyway. What I want to be able to do is detect if a website is open in another tab, then using JavaScript, open up the same website but with a different query string in that same tab
The only way I can think of doing it is if they open the tab on our website first with a name, then next time they click on to the other website, using the same name it should open in the same tab, this isn't preferable as most users will have opened up the other website either by typing it in or from a bookmark
You may play around with 2 things:
localStorage
window.name
The approach could be following: every time your site is open, you store window.name to the local storage. If name is not present, you generate one.
Every time on start-up you check if there is a name saved in local storage, if it is, then you remove the name from the storage, and reload your website like this:
window.open(url,"name");
That should load the page into the open tab, or open new tab with that name.
One problem, however, is that a new window, that was openning your request is remaining in there, cause script cannot close windows that were not open by it.
Related
I am creating a website and on the website, I need about 10-20 more tabs on the user device,
I know how to do this with javascript but the user can disable javascript on the browser which basically stops the entire point of the website, is there any way to do it without javascript (maybe sending a header to Chrome or something that opens a website in a tab)?
There is no way to do that without JavaScript to open multiple tabs at once.
You can make a link open a new tab with the target attribute when clicked by the user, but that is limited to one new tab for one user interaction.
maybe sending a header to Chrome or something that opens a website in a tab
Even if that would be possible with some kind of trick, it would likely be fixed in an update in the browsers, because this will this would be definitely be abused by dubious websites.
Well, the pure HTML way to do that is through the target attribute of any hyperlinked element (A, FRAME, FORM), which shall contain the name of the window that should receive the content of the hyperjump.
Example:
<!--These two hyperlinks redirect the URLs to the same tab-->
local clients
inernational clients
<!--This hyperlink redirect the URL to its own tab-->
providers
Anyway, I warn you not to abuse of this form of forced navigation, because it can chase your user out of your website: The user should be left as free as possible to chose to open or not new tabs/windows. And 10-20 tabs seems to me an overwhelming amount of tabs.
I do not want the webpage to reload if its already open, as this causes unnecessary data to be sent to the javascript application.
If the webpage is not open, I want it to be open.
If the webpage was open but the user used teh tab to load another webpage, i want a new webpage to open,.
If the webpage is open and still on the right url, I do not want any change, I do not want it to refresh.
However I can not seem to find a way to know if the url changed.
I can use cookies if i have to but would rather not. Any suggestions?
Thanks.
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.
So I recently implemented a chrome extension to grab images in an active tab and extract them to a popup for downloading. I would like to give users the option to view the popup window (including the extracted images) in a new Chrome tab.
However, since the popup is created dynamically by appending children to the body of my popup.html, I'm not sure how to pass the HTML for my popup to the new chrome tab.
I tried using chrome.tabs.create({url: chrome.extension.getURL('popup.html#window')});
as found at Open chrome extension in a new tab
but this doesn't seem to be working. Any suggestions?
I'm also developing a Chrome Extension that involves saving down a user's browser data.
Since each time an Extension opens a page (such as popup.html in your case) it opens a new instance of it, the pages and their relevant activity will be independent from each other.
In short you will have to implement some storage. The silver lining is it's pretty simple. Everything you need from manifest to example functions is here:
https://developer.chrome.com/extensions/storage
In your case what I'd imagine you'd want to do is this:
When you pass image urls to your popup page you also save them as items in an array in storage.
Then your pop up page can load in the array as the list to set downloading (or preview depending on use case).
Then either users can delete items from the array, or they are deleted programatically once downloaded.
I can't really be more specific without knowing exactly what your extension is trying to do or how it works, but hopefully that's enough to set you in the right direction.
I have created a jsp for external clients of my application to use to link to the web client. They can specify which client they are in the URL so that when the link opens a window it is named and any other links from that client will open in the same window. Here's an example URL:
mysite.com/redirect.jsp?fromClient=mine&page=awesome
The problem is that when you click on this link, for example from an email digest, it opens the redirect.jsp page which uses window.open() to open the desired page. From the above link, the page that would open would be:
mysite.com/index.jsp?page=awesome
So then I have two pages open, when really I only want one. And since I'm not using javascript to open the first page (it's a link), I can't use window.close() to close it. I've tried working around using window.open('','_parent','') and window.open('','_self','') but neither works.
I know there has to be a better way to redirect than to open a second window from my jsp page, but I don't know what that better way is. Thoughts?
EDIT
Primary goal is for users of external clients to be able to click links in that client and have all the links take them to the same window/tab in a browser. I'm using window.open right now because I can parse the link and get the client name and then supply that in the window.open function.
EDIT 2
I always end up being too vague in these questions. Ok, here's the setup:
An email digest contains a link that looks like
mysite.com/redirect.jsp?fromClient=emailDigest&pageNum=4
Currently, when that link is clicked on, it opens a browser (duh) and then the redirect.jsp page parses that link to get the client name, in this case emailDigest. It then calls window.open('mysite.com/index.jsp?pageNum=4','emailDigest'). This creates a new window with the name emailDigest unless a window/tab with that name already exists, in which case it merely updates the URL in that window with the new one.
I want to either be able to close the original window (the one with the redirect.jsp address) or not have to open that initial window at all.
NOTE
As there are many different clients that want to be able to do this, I cannot guarantee that they will be creating the link with HTML so the target attribute is not the answer.
The correct answer is "No, it cannot be done". If you do not open a window with Javascript then you cannot close it with Javascript. I would always have to create at least 2 windows, which is not what we wanted.
I think you're looking for window.location instead of window.open.
Please use window.location.replace("http://mysite.com/index.jsp?page=awesome");
Reason :
replace(url):Replace the current document with the one at the provided
URL. The difference from the assign() method is that after using
replace() the current page will not be saved in session history,
meaning the user won't be able to use the Back button to navigate to
it.
As haynar says above, why do you open a window and not either:
<!-- content contains the refresh delay in seconds and the target url -->
<meta http-equiv="Refresh" content="1; URL="http://mysite.com/index.jsp?page=awesome">
or use javascript to do the same:
window.location.href = "http://mysite.com/index.jsp?page=awesome";
either works fine and will leave you with one window open.
To get the named window use a targeted link:
Mysite.com
This will automatically set the name property of the opened window.