I’m a new user and new to JS, so please bear with me.
I have 3 files in the same folder, main.html, test.html and script.js
In my main.html, I have
script src="script.js", and <p id = "test"></p>
In my test.html, I have
script src="script.js", and <p id = "tt"></p>
In my script.js, I have a function:
function test() {
document.getElementbyId("test").innerHTML = "this is in main.html"
document.getElementbyId("tt").innerHTML = "this is in test.html"
{
But, when I call the function with a button, only the main.html
with id “test” is updated with “this is in main.html”, how come the
with id “tt” in test.html is not updated with “this is in test.html”?
<html>
<head>
<script type="text/javascript" src="/eel.js"></script>
<script type="text/javascript" src="/script.js"></script>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.5.0/css/bootstrap.min.css">
<link rel="stylesheet" href="style.css">
</head>
<body>
<p id="tt">This is p tag in test.html</p>
</body>
</html>
script.js
function dummy() {
u = document.getElementById("test").innerHTML
f = eel.dummy(u)
document.getElementById("data").src = "test.html"
document.getElementById("menu_table").width='25%'
showdir()
}
async function showdir() {
t = await eel.showdir()()
document.getElementById("test").innerHTML = t
alert(t)
}
When I put the button on the “test” page, it worked from there. I think the issue is that you can’t change a different document (index and test are different documents) using this kind of function.
Are you getting this same message in the console?
Uncaught TypeError: Cannot set property 'innerHTML' of null
at dummy (script.js:5)
at HTMLInputElement.onclick (index.html:13)
dummy @ script.js:5
onclick @ index.html:13
Yes, so this is impossible to do? Any work around or solution? I read about something called localStorage, and I think I can use that, but not sure how.
localStorage is cool, but it’s more like a type of cookie, where the particular document can store something on it. Unfortunately, I’m pretty sure the other documents can’t access it.
Another thing sort of related is the XMLHttpRequest object, where the document can read information from other pages, but again we have the problem where it can’t affect other pages.
I’m kind of a newb, but AFAIK you need to get into the server side of things to do other stuff, so PHP or NodeJS or maybe you can send something to your Python app?
function dummy() {
var el;
if(el=document.getElementById("test"))el.innerHTML = "this is in main.html";
if(el=document.getElementById("tt"))el.innerHTML = "this is in test.htm";
}