This question already has answers here:
How to keep the changes made to DOM by javascript/jquery on page refresh
(2 answers)
How to get JS variable to retain value after page refresh? [duplicate]
(4 answers)
Closed 1 year ago.
Is it possible to save dynamically added HTML elements with JavaScript on HTML page? For example, when I create some HTML element (div, p, li...) using JavaScript, then add it on a page, it appears on the page as it should be, but as soon as I reload or leave the page, and then get back - all those elements disappear. So, how can I do so that they do not disappear after reloading or leaving page (If such is possible).
It is not possible without some backend interaction. But if you need it only for one client (one browser) you can store some details to localStorage and use it on the next load. You have to be aware only one client will be able to see it.
Related
This question already has answers here:
Attach event to dynamic elements in javascript
(15 answers)
Event binding on dynamically created elements?
(23 answers)
Closed last month.
I need to track clicks on content that is dynamically loaded. The content is ads by Google adsense. You include their script in the header of a webpage:
<script async src="https://pagead2.googlesyndication.com/pagead/js/adsbygoogle.js?client=ca-pub-0000000000000"
crossorigin="anonymous"></script>
and then the ads are dynamically placed on different locations of the website.
Because we are facing the problem of fraudulent clicks, we'd like to track who is clicking on them. Is it possible to achieve this through Javascript?
Is it a good idea to intercept all clicks on the web page and then check if the clicked content is an ad?
Are there certain characteristics of the dynamically loaded ads that make them identifieable?
This question already has answers here:
How to hide form code from view code/inspect element browser?
(14 answers)
Closed last year.
I have an input that is hidden and I don't want it to be shown in inspect element. Is there any possible way to do that?
No, there is not. Any HTML element will be accessible through the HTML source, even if generated dynamically through javascript.
If you are trying to secure some information which the client should not have access to, do not send it to the client.
This question already has answers here:
Check if event is triggered by a human
(9 answers)
Closed 4 years ago.
I have some images that are clickable. for each click , users can get some point.
But I want to prevent clicks that do by bots. in fact I want a way to detect that a real user is clicked or a bot.
I want do that in javascript or jquery. if anyone know a plugin that can do that Please introduce me to it.
You can simply assume it’s human, provided access to the page is protected by reCAPTCHA, and subsequent requests carry a CSRF token.
This question already has answers here:
Quickest way to pass data to a popup window I created using window.open()?
(6 answers)
Pass a value from Parent to Child (Open) window
(2 answers)
Closed 6 years ago.
In my application, i need to open a popup and display some results coming from a Javascript function. I open the popup window with the command:
var popup=window.open('popup.html', 'width=500', 'height=500');
where popup.html is an html page that calls the chart.js library for showing some graphs. I need to pass data to this window in order to display the correct graph. I tried a lot of examples, but none worked. How could i solve this problem?
Luca
You could pass basic data in the url hash, change your JS to
var popup=window.open('popup.html#MY_DATA', 'myWindow','width=500,height=500');
and then in the popup.html page you can access the it by looking into the location.hash variable:
window.location.hash
//This will be "#MY_DATA"
This question already has answers here:
Document.write clears page
(6 answers)
Closed 8 years ago.
I am learning how to develop and I wanted to work on a simple "clicker" game using HTML5, CSS3, and JavaScript. I'm looking to practice creating something similar to Cookie Clicker. I have created three icons and they each serve a purpose. I would like to figure out how to display a modified variable on a portion of the screen without clearing the screen or having to resort to a window popup.
Here is the link to the project if anyone is interested in helping:
https://github.com/HandleThatError/Practice
The function in question is the displayPoints function in the master.js file. I currently have the following:
function displayPoints() {
confirm(numClicks);
}
This does what I want. It displays the correct number of clicks. If I click on the middle button twenty times and then click the "Display Points" button, it'll display the right number of points. However, it does it in a popup window. How can I display the number of points inside the browser without using a popup window?
I tried the following code:
function displayPoints() {
document.write(numClicks);
}
This code worked inside the browser but it cleared the screen of the icons, so it's not possible to keep generating points by clicking on the second button.
tl;dr - How can I update variables in real time, on the browser screen, without using a popup window and without clearing the screen? Any help would be much appreciated.
You can use an html element on the page and fill it with data such as:
<span id="numClicksResult"></span>
<script>document.getElementById('numClicksResult').innerHtml=10;</script>
This is an important concept that links HTML and JS:
You need an element to store what you're going to update. This is usually a div.
<div id="myDiv"></div>
Then, in your JS, you need a way of accessing the div.
document.getElementById("myDiv");
This gives you the element, but you need to update the element's value.
document.getElementById("myDiv").innerHTML;
So, you can access the value, but you need to update it whenever there's a click. When the user clicks, you do all of the work you need on your variable and then...
document.getElementById("myDiv").innerHTML = myVar;