Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 7 months ago.
Improve this question
I want to add a message for example: If the user leaves the browser tab, the message "Looks like you're gone ..." should appear. When the user returns to the page, change the message to "Good to be back".
Is it possible to do something like this?
Crate an eventListener on your window, with the load event, and simply show an alert.
And create an event on your window called onbeforeunload (more info about the event), where you show an alert while leaving the page.
Note: onbeforeunload won't work in this snippet, but try putting inside your code.
window.addEventListener('load', (event) =>{
alert("Looks like you are back");
});
window.onbeforeunload = function() {
alert("Looks like you want to leave");
};
You can achieve this with the Page Visibility API
Answered here
Related
Closed. This question needs details or clarity. It is not currently accepting answers.
Want to improve this question? Add details and clarify the problem by editing this post.
Closed 8 months ago.
Improve this question
Good day to all. My question is: is it possible to make the modal window not close after the refetch happens?
At the moment, I have implemented the function of launching the broadcast in a modal window and by clicking on the "Start" button, the variable is refetched, which is responsible for whether the broadcast activity is true or false. And after refetch my modal closes, which I don't want. I can provide code if needed, but it seems to me that this is a more generalized problem.
By refetch you referring to Refresh of the browser?
If so, I would suggest use some redux-persist or managing your own storage over localstorage, on each open/close of the modal, you should update your store/localstorage, and on the next refresh, check if you got modal data stored and open the modal again accordantly.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 2 years ago.
Improve this question
So I was wondering if there is a way to hide you're activity from a webpage that uses JavaScript (And libraries such as AjaX or JQuery).
By activity I mean that I don't what the webpage to know that I'm switching tabs or minimizing the browser, unfocusing and etc.
I know you can track someones activity like so:
$(window).focus(function() {
console.log("YOU'RE BACK")
});
$(window).blur(function() {
console.log("YOU'RE OUT")
});
And I can stop it by writing the following in the console:
$(window).off()
But I'm sure there are million other ways to do so, and I want to make sure that any specific webpage doesn't do so.
So, How can I make sure that no sensitive information leaked?
also note that I don't want to block JavaScript completely, because I want the webpage to still work.
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 3 years ago.
Improve this question
Is there any way to get the text from an alert in JavaScript?
Below I have attached the screenshot of an alert.
Actually I am trying to automate a website using selenium and java and selenium isn't able to handle such alert.
I wonder whether the JavaScript has solution to such alerts.
I am not aware of JavaScript syntax and code styling so posting only a question. Please excuse me for this.
driver.switchTo.alert().getText()
only works for if it is a JS alert,if it is browser alert then it doesn't work
ALERT EXAMPLE:
You should try this, with Selenium:
Alert alert = driver.switchTo().alert();
alert.getText();
The only way I know to do this within javascript is using the confirm popup. It has generic 'OK' and 'Cancel' buttons which I don't believe can be edited and is formatted according to the users web browser. To use the confirm method you write:
if (confirm("Do you really want to leave here?"){
//do whatever
}
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 6 years ago.
Improve this question
I've found a couple other threads containing the same questions, but none of them had an understandable answer. I am supposed to make client side changes, but that is only possible in the .ascx file and if for instance i want to call a function to calculate something and then display it with no page refresh that is not possible :( any easy solutions?
With jquery, you can replace the contents of any existing HTML element using the .html() function. For example,
$("#MyDiv").html("Here is the new text.");
Since the function takes HTML as an input, you can even set the style if you want:
$("#MyDiv").html("Here is some text. <DIV class='foo'>Here is some more text in a different style.</DIV>");
You can also add new elements using .append(), like this:
$("#MyDiv").append("<p>Even more text</p>");
To do this upon a button click, you would use the .click() function. So your code would look something like this:
$("#MyButton").click(function() {
$("#MyDiv").html("You just clicked a button!");
});
Closed. This question needs to be more focused. It is not currently accepting answers.
Want to improve this question? Update the question so it focuses on one problem only by editing this post.
Closed 8 years ago.
Improve this question
Hey any one know how to prevent users to use ad blocker on my site.I just want to request them not to use it on my site..
Make a Javascript file called advertisement.js with this code:
var noadblock = true;
Include it on your page somewhere:
<script type="text/javascript" src="advertisement.js"></script>
The idea is that adblock will block the file called advertisement.js and your var will never be created. So you can use this to take action based on whether the var exists or not:
window.onload = funtion(){
if (noadblock){
// no adblock
}else{
// adblock detected, do stuff here
}
}
Updated cus somone in the comments had a better idea.