I have a piece of code that will open a desktop application through Chrome.
const openDesktopApp = () => {
const url = "path/to/desktopApp";
window.open(url,'_self','');
}
Every time this method is called, Chrome will show a popup if they want to proceed to open the desktop app. This popup is generated by Chrome, how do I add a button handler to the 2 buttons on there? I need to navigate to a different page when they click open and do nothing when they click cancel.
Just add this to your open tag button
href="link to your site that you want"
Related
I'm working on chrome extension and I want to have 2 pages one main popup and then on click on specific button I want to replace it with other one(some settings page) so far I managed to change it using
chrome.action.setPopup({ popup: "settings.html" })
but problem is in fact that it's not immediately propagated, I have to click on extension to close it and click again to open it to be able to see settings page, did I missed something or what is the preferred way in such case?
Web page opens fine inside my WebView but it doesn't respond to print button that is present in webpage. When I click on that printbutton from desktop browser it opens the print interface of browser where I can save the file as PDF. I want to do that same, I have searched a lot but could not find any information, how I can do that?
I want the user to be able to upload text files as input through the browserAction popup for my extension, but I've run into a bit of a problem.
I've been using a hidden input tag, which I trigger with click() when the user clicks on the file upload button. The file browser dialog opens and all seems to work well, until the popup itself closes. And because of the 'webpage' containing the input tag closing, the change event never fires.
Since the extension already has a background script for populating the popup with persistent data, I figured that I could create the input in the background script and trigger that with .click() when user clicks on the file upload button in the popup.
But, even though the click event fires for the input in the background script, the file browser dialog does not open.
I figure that reason for this is that Chrome does not allow the file input to be triggered programatically unless it's through a user action, but I'm not sure. This is how I tried;
popup.js
//Button in popup which should open file broswer dialog
//when clicked
browseBtn.addEventListener('click', function() {
chrome.runtime.sendMessage({msg: 'file_input'});
}
background.js
var fileInput = document.createElement('input');
fileInput.type = 'file';
fileInput.accept = 'text/*';
fileInput.addEventListener('click', function(e) {
console.log('fileInput clicked');
}, false);
fileInput.addEventListener('change', function(e) {
console.log('fileInput changed');
console.log(this.files);
}, false);
chrome.runtime.onMessage.addListener(function(e) {
if(e.msg === 'file_input')
fileInput.click();
});
I know that the click event is triggered because fileInput clicked is logged. But, the file browser dialog does not open.
I also tried a variation of this code using chrome.extension.getBackgroundPage() to directly call fileInput.click(). Again, click event was fired but the dialog did not open.
My question is; is there a way to allow the background script to trigger the file input to open the file browser dialog? That would be the best solution, because it would allow the extension to extract the data from the specified file even if the popup closed somehow.
If not, is there a way to avoid the popup from being closed when the file browser dialog opens? From what I found, using the hidden input tag was supposed to be a work around, and it does work for some cases, but not for all users.
For example, I was able to upload files without popup being closed on Chrome, Windows 7. But, on Chromium, Ubuntu 14.04, the popup closes the instant the file browser dialog opens.
Any help is appreciated.
It looks like this might have just been fixed, I'm waiting for it to be available as well!
I have a web application where I have four/five icons in the default page. On click of these icons i am redirecting to some URL in new tab of already opened chromium browser instance using javascript. Below is the javascript code snippet that I am using to launch the URL in new tab of already opened chromium browser instance. Here I am manually clicking the icon
window.open(myURL, '_blank');
But the issue is when I am trying to open the same URL using the same code and programatically triggering the same code to open the URL in new tab, it opes up as a Pop Up but not in a tab. Below is how I am trying to pragmatically open the URL. I am calling the click event of the Icon in the default page using some script rather than manually clicking the icon.
$('#myIconId').click();
If somebody could please help me out. TIA
give a try to use
content of the anchor
Although You shouldn't force user to open new pages or new tab without showing them a hint on what is going to happen before they click on the link.
Above code may or may not work on all browser, please test before making live.
UPDATE
Ref : Programmatically open new pages on Tabs
I want to prevent users from reloading the page each time to get updated dynamic content. So I have used this code:
window.onbeforeunload = function() {
return "Dont need to reload the whole page. Just reload the section";
}
It's working fine except when an user closes the browser's tab/window, the same message is showing also. But I want to show the message only for reloading/F5 button, not for closing the browser's tab/window. What event handler should I have to used for that purpose?
You can physically disable the f5 button, to get functionality similar to what you want:
Disable F5 and browser refresh using javascript