How to detect active page / input box in browser extension? [duplicate] - javascript

This question already has answers here:
How to access the webpage DOM/HTML from an extension popup or background script?
(2 answers)
How to determine which html page element has focus? [duplicate]
(5 answers)
Closed last month.
From the browser extension (running in the background) I would like to detect that user placed the mouse pointer in the password input box and trigger some event(s) e.g. pop-up an icon to prompt the user for action (autofill the box with the password, provide some options, etc) similarly as eg. 1password does in the screen capture below.
How this can be accomplished e.g. in JavaScript?

Related

Determine via Javascript if page load was via a browser bookmark vs clicking on some link? [duplicate]

This question already has answers here:
Determine if a request was via a browser bookmark/favorite vs a link?
(3 answers)
Closed 9 months ago.
Say I am on my React app at http://mysite/. Then I either
(A) Click to navigate to https://mysite/#/myroute
(B) click on a browser bookmark to https://mysite/#/myroute
Can the client-side JavaScript route i.e. MyRoute know whether the navigation was via a browser bookmark vs clicking on some link?
Can the client-side JavaScript route i.e. MyRoute know whether the navigation was via a browser bookmark vs clicking on some link?
If you mean "clicking on some internal link", then yes. But there is no way to distinguish a click on a bookmark from a click on an external link that leads to your website.
In any case, you leverage the document.referrer property: if it's equal to an empty string, the user navigated from an external source, otherwise it will contain the previous internal url.

How to prevent the user from leaving my page [duplicate]

This question already has answers here:
Prevent a webpage from navigating away using JavaScript
(10 answers)
Prevent user to leave my page in javascript
(2 answers)
Closed 4 years ago.
I'm trying to make an online test using spring-mvc and html, css, jquery and I want to prevent the user that is doing the test from leave the test screen while doing the test. Does anybody know how I can do that?

Automatiaclly crop website before printing the page [duplicate]

This question already has answers here:
remove url and print text from the printed page
(4 answers)
Closed 7 years ago.
I have a HTML file that triggers print() when you click a button. How do you crop the page so the site name and url does not show up?
You cant, including URL and/or title is up to the browsers print dialog.

How to open a tab and display text in blank page [duplicate]

This question already has answers here:
Open window in JavaScript with HTML inserted
(8 answers)
Closed 7 years ago.
When the user click somewhere, I want the browser to open a new tab and display the text I want him to.
I want something exactly like a link with a blank target to a text file on my server, except that the text is generated on the client side by my script, so no interaction with the server.
Assuming that you are just looking to display text in a file. You can build a string with Javascript and then open a new window with that code below.
Please note, that popup blockers do not like window.open.
var str = 'hello world';
window.open('data:text/plain;charset=utf-8,' + str);

Force page to refresh/reload if user clicks on back button in browser [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Cross-browser onload event and the Back button
How can I force a view/page to refresh when a user clicks browser back to that page?
use onunload
<body onunload="alert(unloading page')"></body>

Categories

Resources