So, imagine a person opening an online gaming website(for example krunker.io) in chrome, and what I want to know is whether there is a way to detect if a url(in this case "https://krunker.io/*") is open and to immediately close the tab(or the browser) using a Google Chrome addon(or even an outside application is fine).
The window.close() method does not work, as the person him/herself is the one who opens the tab/window, not the application
To close a tab, you can use the chrome.tabs.remove method.
// retrieve the id of the tab to close
$tabToCloseId = retrieveIdOfTabToClose(); //To write by yourself
chrome.tabs.remove($tabToCloseId);
Related
Using a pretty clunky framework for a website, when a user opens a document, two pop ups are generated to support split screen. The first pop up is generated from a user clicking on a table, the second pop up is generated from the first pop up. However the method in which the user submits the first pop up (which closes the second pop up based on an onbeforeunload event does not have access to the variable that represents the second pop up.
From what I have read the below should be a way to grab a reference to the secondPopUp from the firstPopUp (since window.open is originally run on the firstPopUp) as long as I have the windowName and am in same domain.
'''var existingWindow= window.open('','secondPopUp');'''
However this solution weirdly only works when Google Chrome developer tools are turned on.
Is there anyway to get this to work without having to rewrite how the window.opens are called? Seeing it work with Chrome Dev Tools on makes me think there must be some trick.
I have a GWT application which has many firefox windows. I need functionality to close all these windows with a single click on a button. I know the window.close() function, but it only closes the current window.
I wonder if there is a firefox plugin or anything what can help me achieve this functionality.
In Firefox the File menu contains an Exit button what terminates the program, but i can't find a way to call this from javascript.
You cannot close other windows with script that didn't open them. But
var newWindow = window.open( url );
newWindow.close();
will open new tab with url and then you will be able to close it with newWindow.close();
When a new window is opened with window.open(), a reference to the new window is returned.
This means var window1 = window.open("example.com", "windowName"); will allow you to close the this new window later with window1.close();
Windows are often opened this way to address your problem, though if the windowName specified existed already, the existing window would be used to load the page instead, and the variable would refer to the existing window.
EDIT: This explains browser windows and associated window control JavaScript here
I created a simple firefox add on using addon-builder that installs & successfully appears in the add on toolbar at the bottom of the browser.
If I press ctrl-n, open new tab, open new window, or open private browsing window in firefox, then I see and can use my addon. However, if another site programmatically opens a window using window.open(), then my addon doesn't appear.
Is this by design? Or is there a setting that I can include in my addon so that it always appears, even if the window was opened through window.open() instead of ctrl-n?
When sites open with window.open, they specify which parts of the browser UI will show. You may be able to place it somewhere less likely to be removed, like the navigation toolbar. The add-ons toolbar sounds like it's going away soon, anyway.
So, I have my chrome extension, runs in background fine. And every few hours it uses the notification API to ask the user a question.
If they click one answer we open a tab in the current window.
Problem: If there are no chrome windows open (i.e. the extension is running as part of "Let google chrome run in the background" option), the tab doesn't open.
Here's the code which works fine as long as there is at least a single chrome window open:
// tried this too: chrome.windows.create();
chrome.tabs.create({url: pathToGo});
How to make "chrome.windows.create()" actually make a window if there are none already open.
Use chrome.windows.getAll(object getInfo, function callback) APIs to get all open windows.
If in the callback, the array of windows is empty, create a new window using chrome.windows.create(object createData, function callback).
Use chrome.notifications API if you are unable to create new window.
http://developer.chrome.com/extensions/notifications.html
I'm developing a tool that lets you open multiple pages at once with a shortcut, to be used for things like opening your daily sites or querying multiple search engines for a phrase. In Firefox, Internet Explorer and Opera, assuming you've unblocked pop-ups for the domain, the code works as expected.
Chrome, however, opens the sites in new windows instead of tabs if the links are opened automatically when the page loads. If openAll() is commented out and the button is clicked or a key is pressed, the pages open in tabs. Note it's calling the exact same function.
The best solution I've found (which isn't saying much) is the One Window extension. It works, but you can see the new window open then get sucked back in, and it keeps you from opening new Windows with Ctrl-N, forcing you to drag tabs out to use another Chrome window.
I can understand there not being a programmatic way to change this because it's a browser setting, but as a user of the tool it's annoying to have the sites all open in new windows. Is there a Chrome setting or extension that will open links in tabs when they're loaded without user input? I realize opening a bevy of windows is the very thing browsers aim to stop, but this is one time where I want to allow it.
<input id="openAllBtn" type="button" value="Open all links"> (Or press any key)
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.6.1.min.js"></script>
<script type="text/javascript">
function openAll() {
window.open('http://yahoo.com/');
window.location.replace('http://www.bing.com/');
return false;
}
$(document).ready(function() {
$(document).bind('keypress', openAll);
$("#openAllBtn").bind("click", openAll);
openAll();
});
</script>
Here's a Fiddle of the code: http://jsfiddle.net/sfzjR/
Is there a Chrome setting or extension
that will open links in tabs when
they're loaded without user input?
Check out the create method in the chrome extension docs. By default it will open a new tab, you can optionally specify the window you want that tab to open in, and give the tab a url.