JavaScript detect hash select/copy [duplicate] - javascript

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Detect focus on browser address bar?
Simple question. My guess is that it isn't possible, but still doesn't hurt to ask:
Does anyone know if it is possible to detect the following events:
click in the URL bar
URL bar text is selected
URL bar text keypress
URL bar text copy to clipboard

None of these are possible. You can't detect events on the browser window as event handling is limited to the document.

You can somehow intercept this kind of events in Firefox, using XUL, but only in the context of an extension (maybe it's possible to do the same in Chrome too).
see:
Responding to address bar key events in Firefox Add-on
There's no way to intercept these events from the loaded page.

Related

How to detect a pushState / replaceState that doesn't trigger onpopstate [duplicate]

This question already has answers here:
monitoring history.pushstate from a chrome extension
(3 answers)
How to detect page navigation on YouTube and modify its appearance seamlessly?
(2 answers)
Closed 7 years ago.
About the popstate, the documentation says this:
Note that just calling history.pushState() or history.replaceState()
won't trigger a popstate event. The popstate event is only triggered
by doing a browser action such as a click on the back button (or
calling history.back() in JavaScript).
So for example, at youtube, if you navigate to another video, the url is changed but how can i detect that change since it wasn't triggered by a browser action?
I would like to do this at the content script, but if impossible, i could do it in the background.
PS:Youtube is just the easiest example of this, so youtube specific solutions, or solutions that depend on youtube maintaining certain id's in the html are not what i'm looking for.
You can use webNavigation API and listen for onHistoryStateUpdated event in your background.
e.g:
chrome.webNavigation.onHistoryStateUpdated.addListener(function () {
// do something here
})

javascript should run only if tab/browser window is focused [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Detect If Browser Tab Has Focus
I have a simple java applet that captures client's screen. With the help of a piece of javascript code, I am able to call the applet and capture the active screen picture.
But, even though it only captures active screen with a click on a button, users are likely to manipulate the process by switching to some other tab with ALT TAB while capture process. I want to make sure that capturing must be done only if page is loaded and page is focused.
So far, I found this piece of javascript code which doesn't seem to be working correctly. Sometimes it gets stuck at the focus even though the page is minimized.
<script language="javascript">
window.onpageshow = function(e) { console.log('pageshow'); };
window.onfocus = function(e) { console.log('focus'); };
</script>
So are there any suggestions to what I am trying to achieve or any other solutions.
Try using document.hidden it's part of the page visibility API

Notification When Chrome Exits [duplicate]

This question already has answers here:
Closed 10 years ago.
Possible Duplicate:
Event onBrowserClose for Google Chrome?
Is it possible to detect when the user exits the Chrome browser, so I can process some data right before they exit? I have looked into using chrome.windows.onRemoved.addListener(function(integer windowId) {...}); but it only listens for a window and not the entire browser.
Well, no.
There is no Close event, and Chrome doesn't guarantee that all others pending events will be fired before closing (will be fired at all).
I personally researched this topic while writing the "History Eliminator" extension, that would erase your browser history on close.

How can I specify a hotkey for my browser action? [duplicate]

This question already has answers here:
Open Browser Action's Popup with keyboard shortcut
(3 answers)
Closed 5 years ago.
Is it possible to specify a hotkey that will activate a Google Chrome browser action?
No, you can manipulate almost every other aspect of the browserAction and the popup (including closing it) but it cannot be triggered programatically.
#hamczu is right that the only way to bind global keyboard shortcuts is to inject a Content Script that listens for keystrokes in every page.
However you will not be able to make those keystrokes (or anything else) trigger the browserAction.
I think you should look to Vimium project source. Global hotkeys are done by binding keyboard events in content script and communicate to background page. As authors say in Wiki there is no way "to add global keyboard shortcuts (without using a content script)".
Unfortunately I have found related issue in the bugtracker and it seems there is no way to so so.
The chrome.commands api enables the user to bind hotkeys (with your suggestion for the hotkey) that will trigger commands such as opening the browser action.
Duplicate of answer.

Cross browser window close event [duplicate]

This question already has answers here:
Closed 12 years ago.
Possible Duplicate:
Close /Kills the seesion when close the browser or tab
Is there a solution for cross browser event. I need to check if user closes their window and to throw an ajax request to my database to sign them out.
I've looked everyone but most cases its not working in all browsers. Anyone have a solution? Or Alternative on how to do this perhaps a conditional statement depending on the browser?
Thanks!
I don't think such a thing exists. You can try an onunload, but that also fires when you refresh the page. This question has been the bane of many that want to do what you're asking for.

Categories