can anyone please give the syntax for chrome notification containing buttons??I am not sure about the syntax for adding buttons to notification box in chrome.Can anyone please help me??
This is my code for notification.
chrome.notifications.create(
'id1',{
type: 'basic',
iconUrl: '/icon_128.png',
title: 'Althe Frazon',
message: 'Lorem ipsum',
buttons: [{ title: 'Call'
},
{ title: 'Send Email'
}],
priority: 0
},
function() { /* Error checking goes here */}
);
notification.show();
Using this code the notification is shown.But the buttons are not shown.Anygone please guess the reason.Why my buttons are not shown??Please help me
For anyone landing on this page looking for a way to add buttons to notifications or trying to figure out why no buttons are shown:
This answer explains in detail how to create notifications and how to add buttons.
Nonetheless, the buttons are not displayed on some distributions of Linux.
This is a known issue (still holding for Chrome version 31.0.1650.57) and is dependent on Views shipping on Linux.
Related
I have a chrome extension. In its background script I want to present a confirm() dialog box to accept (Ok/Cancel) input from user. Have no problem doing that.
The only problem is that the title of message shows up as "chrome-extension://32_char_extension_id". Not what I want to see.
On the other hand in the safari extension (global.html) the title shows up as the "Extension name".
Would be nice to have the same functionality in Chrome Extension.
Any idea if there is a way to see extension name in the message box instead of the ID.
Anything I"m doing it wrong ?
I understand confirm() is the not the recommended solution for prompt to take user input (as it is a blocking call). But this seems like a quicker solution for what I"m doing.
The other alternatives I"m looking into using JQuery message boxes. But if I can resolve this thru simple confirm(), it would be great for now.
Probably, you should use the chrome.notifications API to display the dialog so that you ask the user something in this case. You can show a notification which has two buttons by like the following code:
chrome.notifications.onButtonClicked.addListener((notificationId, buttonIndex) => {
// If buttonIndex == 0, Ok button clicked.
chrome.notifications.clear(notificationId, wasCleared => { ... });
});
chrome.notifications.create("notificationId", {
type: "basic",
iconUrl: "SOME_ICON_PATH",
title: "YOUR_EXTENSION_NAME",
message: "SOME_MESSAGE",
buttons: [
{
title: "Ok"
},
{
title: "Cancel"
}
]
});
Of course, you need to get a "notifications" permission from the user.
You can't change window.confirm() title, it is for anti-phishing.
You should try other approaches such as Bootstrap Modal
I have an extension that implements a browser action.
Of course, the browser action is allways visible, but it has a special significance in certain urls. So, I use filtered events to listen to those urls and set the proper badge
chrome.webNavigation.onDOMContentLoaded.addListener(
function(tab){
chrome.browserAction.setBadgeText({
text:'bdge',
tabId: tab
});
},
{'url':[{hostSuffix: 'somedomain.com', pathPrefix: 'somePath/'}]}
);
Is there some "elegant" way to reset the badge when the user navigates out from that page, without listening every single tab navigation?
Should I execute a content script to hang on some exiting event and send a message?
Thank you very much,
It seems to me that a good solution would be to use chrome.tabs.onUpdated.
In your background page, you would have something like that:
chrome.tabs.onUpdated.addListener(function(tabId, changeInfo, tab) {
// using a regex or however else you want to test the URL
if (/somedomain\.com\/somePath\//.test(changeInfo.url)) {
chrome.browserAction.setBadgeText({
text: 'bdge',
tabId: tabId
});
} else {
chrome.browserAction.setBadgeText({
text: '',
tabId: tabId
});
}
});
I know you wrote "without listening every single tab navigation" but I'm not sure why you want to avoid this.
This is what documentation doesn't tell you: Chrome actually resets badge automatically when user navigates away.
When you set a browser action's badge only to a specific tab, like
chrome.browserAction.setBadgeText({
text: 'ABCD', // My badge's text should be only 4 characters long
tabId: 1234 // Any tab, ussually a var here, not a constant
});
Chrome shows the badge on the browser action button only when that tab is the active tab in the window. Its text resets to '' when the user navigates away in that tab. No need for special action to reset it.
I have a problem calling crossrider setPopup multiple times based on
some condition like if user is logged in then only show the Popup on
browser action click otherwise show a login popup.
But, it is calling only once after that.
function handler(evtXHR) {
if (invocation.ready State == 4) {
if (invocation.status == 200) {
//alert("successs : "+invocation.responseText);
if (invocation.responseText == "demo") {
//buttonState = true;`enter code here`
appAPI.browserAction.setPopup({
resourcePath: 'html/New popup.html',
height: 1000,
width: 1000
});
}
In general, calling setPopup more than once changes the content for the subsequent button click. However, having reviewed your code, I can see that there are several issues with the extension, for example, for correct operation the button must be enabled in the Settings > Browser Buttons (see introduction to browserAction and How to add a button to your extension).
I don't think StackOverflow is the appropriate forum to assist you in debugging the extension issues and therefore, invite you to email our support channel (support#crossrider.com) with the details you provided and I will be happy to assist you further
i have this problem. I have a dialog running on jquery mobile. With this dialog i perform a search and if the search is successful with knockout i update my view-model. The problem is that i would reuse the dialog to update items that have same json structure but are placed in different position in my vm (in other words i would not create a specific function and specific search dialog for the same type of object but use always the same and at runtime update the correct/current item). My idea was to pass, when open dialog, the context of current elemet to update but i have no success in this.
Is this possible. What is the best practice to perform this?
Thanks in advance
I have made a custom binding for this, in combo with the native template binding of knockout you can get this behaviour, please see my bindings here
https://github.com/AndersMalmgren/Knockout.Bindings
Examples http://jsfiddle.net/H8xWY/7/
Code
<div id="dialog" data-bind="dialog: { autoOpen: false, modal: true, title: dialogTitle }, template: { name: 'dialog-template', data: dialogItem, 'if': dialogItem }, openDialog: dialogItem"></div>
Does anyone know if it's possible to add to the mouse right click menu in Chrome another option which would communicate with an extension?
I mean, after installing an extension, another option would appear in the mouse's right click menu which will send to a listener opened by the extension the data.
Here is the solution:
rightClickHandler = function(){
//Do your stuff over that selected context menu
};
chrome.contextMenus.create({
title: "Bitly Short Link",
contexts:["link","selection"], // ContextType
onclick: rightClickHandler // A callback function
});
In manifest.json, have this permission:
{ "permissions": ["...", "contextMenus"], }
Hope it helps!