Passing text to a popup window opened in a JS function [duplicate] - javascript

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"

Related

Is there a possible way to hide the input from inspect element? [duplicate]

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.

Saving dynamically created HTML elements with JavaScript not using PHP? [duplicate]

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.

Python selenium generates stale element reference error when calling hover function [duplicate]

This question already has answers here:
StaleElementException when iterating with Python
(2 answers)
Message: stale element reference: element is not attached to the page document in Python
(1 answer)
Closed 2 years ago.
I need help with my selenium project.
I'm trying to get the data from all the post of a given instagram profile by hovering each post at a time but when it reaches the last posts and calls the hover.perform function I get this error.
selenium.common.exceptions.StaleElementReferenceException: Message: stale element reference: element is not attached to the page document
The error is generated because is unable to find the posts but I can't figure out why.
This is the link to my code: https://github.com/binksdev/pythonApps/blob/master/InstaScrapper/scrapper.py

Link without tracking source web page [duplicate]

This question already has answers here:
Remove http referer
(10 answers)
Hide Referrer on click
(8 answers)
Is it possible to remove the referrer in PHP before redirected?
(5 answers)
Closed 5 years ago.
I am working on a web with php (laravel 5.4) and I have to generate several links that the user clicking on them does not let you know that the click originated from my web page. The idea is that it seems that the user wrote the link directly in the browser, and that does not relate in any way that clicked from my website. how can I do it? Thanks for your help.
You can do that using javaScript. You need to define a function that accepts a url as parameter and calls the javascript window.open().
Make a regular tag and in its href attribute pass javascript:void(0); so that the default link click action is stopped.
Now define an attribute onClick and call your defined function here and pass the url you want to open.
Please see the example below:
<script type="text/javascript">
function openURL(url)
{
window.open(url);
}
</script>
GOOGLE

Displaying javascript variable without clearing screen [duplicate]

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;

Categories