I want it so that every time a button is clicked, a new page with a random name is generated (i. e. HuJ8a7-Op_z6.html).
How can i do that using HTML & JS?
I want it so that every time a button is clicked, a new page with a random name is generated (i. e. HuJ8a7-Op_z6.html).
How can i do that using HTML & JS?
You would need to use server side code to do this.
Wait, i think i just figured it out…
<html>
<head>
<title>Website</title>
<script>
function test() {
var opened = window.open("test.html");
opened.document.write("<html><head><title>MyTitle</title></head><body>test</body></html>");
}
</script>
</head>
<body>
<h1>Welcome</h1>
<p>
<button onclick="test();">Link to new page</button>
</p>
</body>
</html>
I’ll add the randomly-generated string later,
Anyways, i need it to create a new page. However, this will just open about:blank and add the specified code in there!
Just a heads up that this will not save, but glad you figured it out.
So how do i make it create a new page?
Read this First
Yeah, i did.
I would recommend that you look into file creation in what server side language you prefer.
JS? Is that possible with JS?
Client side? No.
I guess that you only know HTML and the js. But want to do many things that need server side of code. So if you have not of the already you should learn node or the php
NodeJS?
I’m using hello-sqlite
Just to understand , do you know of the node js language ?
Long-story-short: Kind-of
Like we said, please look into file creation in your server side language.
That’s makes no sense. You of either know it or dont
If you’re learning Node, you can start by reading the docs, it’s not as painful as some other docs
Mark that post for the answer @no_one if you are the done with help and understand
var fs = require('fs');
fs.writeFile('mynewfile3.txt', 'Hello content!', function (err) {
if (err) throw err;
console.log('Saved!');
});
Is this right?
The docs should tell you if it is right or not. Did you read them?
Uhm… nope
Then of Read them
Well, the docs are a great place to start!
I do at least one visit to php.net per day
if (err) throw err;
I think i understand what this means!
if an error appears, go ahead and throw it out the window
Is the react server of side?
Yes, it is.
Ok, i think i’m almost done.
The Javascript function thingy isn’t working nicely with NodeJS…
Could you watch a tutorial on node? You can’t run nodejs client side.
We can help you fix errors, point towards official documentation, help you understand something but not teach you a new language or framework. If you want to learn a new language or framework, you can 1) read the docs, 2) take courses on them, 3) read articles about them and 4) watch tutorials. Please do not find this mean or offensive.
This is solved, however, i’ve ran into another problem here.
I’ll solve it myself
@code-alt did you install fs on the project?
I’m not a node person- but i’m pretty sure it comes pre-packaged
ya it’s made instantly when you create a node app
The name is actually occupied in npm to prevent someone from writing a malacious fs module
fs
in their package.json for some reason
Still getting almost 800k downloads per week.
This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.