Quantcast
Channel: Active questions tagged javascript - Stack Overflow
Viewing all articles
Browse latest Browse all 139833

How do you save your post data on your blog even after reloading?

$
0
0

I'm trying to create a blog but it doesn't work. I want the blog to have it so it can save the posts in the blog so every time I reload it still has the same posts on the website (Off-topic question: How when you go onto for example stack overflow, it automatically creates a page for that question when you submit it?). But anyway, when I reload my website it resets the page and all the posts are lost! Currently, my code is this:

blog.html

<!DOCTYPE html>
<html>
    <head>
        <title>My Blog</title>
        <script src='script.js'></script>
    </head>
    <body>
        <h1 style='text-align: center;'>My blog</h1>
        <button onclick=add_question()>New Post</button>
        <br><br><br>
        <div id='question area'>
            <span style='border: 7px black dashed;display:inline-block;align-self: center;'>
                <h2 style='text-align: center;'>Welcome!</h2>
                <pre style='text-align: center;'>This is where all my blog posts are!</pre>
            </span>
            <br>
        </div>
    </body>
</html>

And this

script.js

function add_question() {
    let title = prompt('Enter a title');
    let paragraph = prompt('Enter a paragraph');

    let question_area = document.getElementById('question area');
    let questionTag = document.createElement('span');
    let titleTag = document.createElement('h2');
    titleTag.innerText = title;
    let pTag = document.createElement('pre');
    pTag.innerText = paragraph;

    [titleTag,pTag].forEach((tag) => {tag.style.textAlign = 'center'; questionTag.appendChild(tag)})
    questionTag.style.border = '5px black solid';
    question_area.append(questionTag,document.createElement('br'));
}

So what do I need to do to fix this?


Viewing all articles
Browse latest Browse all 139833

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>