New pages using HTML

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.

3 Likes

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.

4 Likes

So how do i make it create a new page? :laughing:

Read this First

5 Likes

Yeah, i did. :expressionless:

I would recommend that you look into file creation in what server side language you prefer.

2 Likes

JS? Is that possible with JS?

1 Like

Client side? No.

2 Likes

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

1 Like

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.

3 Likes

That’s makes no sense. You of either know it or dont

1 Like

If you’re learning Node, you can start by reading the docs, it’s not as painful as some other docs


When glitch adds autocomplete your life will be made a bit easier
5 Likes

Mark that post for the answer @LankyBox01 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?

1 Like

The docs should tell you if it is right or not. Did you read them?

2 Likes