Chrome extension popups are designed per the FAQ to close when clicked away from.
I have a firefox add-on that will remember the text typed into the text area when the popup is clicked open or closed.
I assume this is the case because the popup merely opens and closes the html, as opposed to the chrome version which calls window.onload each time.
The chrome extension popup however seems to call popup.js each time you click the icon, which I assume is because popup.js is linked from popup.html because page scripts have to be "moved out" in chrome for security.
Is there a way to keep data typed into a textbox, when the extension reloads and "erases" the text?
Anytime the content of the textarea changes, store the new value in localStorage. When the popup loads again, check local storage for a value and populate the textarea.
Related
I searched all over and haven't found an answer. I'm developing a Chrome extension and would like to know how to make the popup window stay open if the user chooses to open a link in a new background tab. (For example, clicking on the link while pressing the "ctrl" key.) Currently when I do that, the popup closes even though the user stays on the current tab.
It is different than How to keep Google Chrome Extension popup open?, as that's talking about when the user focuses on a different window, then the popup closes. I'm talking about when the user specifically stays focused on the popup, as in the example given that the user presses "ctrl" while clicking on the link, that the focus stays on current page.
chrome.tabs.create({ url, active: false });
From the docs:
active (boolean, optional): Whether the tab should become the active tab in the window. Does not affect whether the window is focused (see windows.update). Defaults to true.
Ref: https://developer.chrome.com/docs/extensions/reference/tabs/
How to get a warning massage if i accidently click the close button of the chrome browser which have multiple tabs opened at that time?
I am a regular user of Crome and having this problem while using it. I normally open multiple tabs inside a single browser but sometimes i accidently click the close button of browser and as soon as the button is clicked crome does't give any warning issue about multiple active tabs and close the entire window.
Is the end user like me is browsing on normal crome window then he can open the websites again by checking the web history but if he is browsing inside private browser then he can't do anything(this happens with me very regularly because i normally browse in private browser). On the other hand if you accidently click the close button in mozilla which have multiple tabs open it throws a warning massage to the user and asks for his wish.
Go find an extension called "Keep One Pinned Tab". It may not be exactly the function you need, but if you search for other extensions, I am sure there is such an extension that does just that. If you can't find one, I suggest to learn how to develop extensions and make one yourself, you can share it with others when it's done.
I want to build app that would allow me to open website, select some data from this website and send them to my server. I imagine that it works in this way:
Application id displayed in browser sidebar sidebar
I open certain website
Select address (City) on opened website
Click "City" button on sidebar
"City" value is copied from website to sidebar
Select address (Zip code) in browser
Click "Zip code" button on side bar
"Zip code" value is copied from website to sidebar
... (and so on)
Finally I click "submit" button on sidebar and data is send to server.
What will be better option for such use case? Chrome app or chrome extension? I am not sure if there is way to display sidebar using chrome extension. I also haven't seen in reference option to open certain url in chrome app. Any advises will be appreciated.
I guess an extension would be more appropriate as it is just one click away from the website you want to select some data from. The user interaction could be done in various ways:
select text and use the context menu (right mouse click) to activate the extension logic
activate extension via toolbar and add UI as a part of the website being viewed or in a separate window
You can pop up a window, but it will disappear when you click back on the website. You can manually create a "sidebar" by having your extension open a new window whose url is inside the extension and subsequently manually placing it alongside the browser window.
Unfortunately there is no sidebar feature for chrome extensions. That would be cool if there were, though.
I have implemented a chrome extension. Was wondering if the popup.html can be opened in a new tab? Every single click on the page, and the popup disappears :( .. Was wondering if I can stick it to the page or is there a way to open the extension in a new page?
Yes, a popup page is just a normal extension page, you can do the following to open a new popup tab from the background page. I use that every time when the user first installs the extension, I open the about page, you can do the same for the popup page.
chrome.tabs.create({url: 'popup.html'})
For one of my extensions, My Hangouts, I have a small "open as tab" button within the popup, I bind the click event for that link to execute this:
chrome.tabs.create({url: chrome.extension.getURL('popup.html#window')});
The reason why I passed the hash is because I wanted to add more content when the user opens it in a popup because there is more real estate to play with.
Within the popup, I use normal JavaScript to differentiate whether I opened the tab in the new tab page or in a normal page like the following:
if (window.location.hash == '#window') {
this.displayAsTab = true;
}
You can do tricks like this to make your extensions user experience better.
here is the same issue: Chrome Extension: onclick extension icon, open popup.html in new tab
use:
chrome.tabs.create({'url': chrome.extension.getURL('popup.html')}, function(tab) {
// Tab opened.
});
property "pinned" to stick the tab.
I am developing a chrome extension. I am able to pass a message from background page to popup extension when a context menu is clicked if i open the popup page with "Inspect pop-up" selection. Because it stays open in this way.
But if I click the context menu when the popup page is not opened, no message received by it.
Do you have any suggestions to open popup automatically, make it stay open or send message to it when even if it is not active.
There is no way to pragmatically open a popup window. Popup windows are only active when the popup is open which is why you cant send messages to it when it is closed.
You could either queue messages in the background page and have them retrieved the next time the popup window is opened. Or depending on the functionality you might look into using HTML5 desktop notifications instead.
Instead of sending stuff to the popup, the popup should request what it needs when it is opened.
Because the popup is just an HTML page, it doesn't exist until it has been opened.
Basically, like abraham mentioned, you would store any information in the background, using localStorage or chrome.storage. When the popup opens, it should then use the chrome.extension.getBackgroundPage() function to get a reference to the background, which can provide access to the stored information.
If you are using localStorage or chrome.storage, you may be able to access it directly, without using the background, as storage is shared across the whole extension.