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 @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?

1 Like

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

2 Likes

Uhm… nope :eyes:

Then of Read them :slight_smile:

Well, the docs are a great place to start!

3 Likes

I do at least one visit to php.net per day :slight_smile:

  if (err) throw err;

I think i understand what this means!
if an error appears, go ahead and throw it out the window

2 Likes

Is the react server of side?

Yes, it is.

1 Like

Ok, i think i’m almost done.
The Javascript function thingy isn’t working nicely with NodeJS…


Could someone help?

Could you watch a tutorial on node? You can’t run nodejs client side.

5 Likes

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.

6 Likes

This is solved, however, i’ve ran into another problem here.
I’ll solve it myself :slight_smile:

1 Like

@code-alt did you install fs on the project?

1 Like

I’m not a node person- but i’m pretty sure it comes pre-packaged

2 Likes

ya it’s made instantly when you create a node app

6 Likes

The name is actually occupied in npm to prevent someone from writing a malacious fs module


however for some reason you can get it, if you ask nicely. I’ve seen older projects have fs in their package.json for some reason
1 Like

Still getting almost 800k downloads per week.

2 Likes

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.