Back to top Button

writeas

#1

Hello! :slight_smile:

Is there any way to add a “back-to-top” button or text to the blog?

I think it would be handy… :wink:


#2

Hey, you can do that today with a bit of Javascript:

var topP = document.createElement("p");
topP.style.textAlign = "center";
topP.innerHTML = '<a href="#">Back to top</a>';
var cont = document.getElementById("wrapper");
if (cont !== null) {
    // Add to blog index and tag pages
    cont.appendChild(topP);
} else {
    // Add to individual blog post page
    cont = document.getElementById("post-body");
    cont.insertAdjacentHTML("afterend", topP.outerHTML);
}

#3

Nice, that worked! :slight_smile:
Is there a way to add utf-8 encoding to replace the text with Greek translation?
I tried to do it and I only got question mark symbols.


#4

Awesome!

I might have to make some changes on our end to get Greek text working. Could you send me an example URL or the exact JS you’re using (either privately, or on this thread)? Then I can make the changes and verify that they work.


#5

Sure! The code I want to use it this one - nothing weird, I just translated the “Back to top” text.

var topP = document.createElement("p");
topP.style.textAlign = "center";
topP.innerHTML = '<a href="#">Επιστροφή στην κορυφή</a>';
var cont = document.getElementById("wrapper");
if (cont !== null) {
    // Add to blog index and tag pages
    cont.appendChild(topP);
} else {
    // Add to individual blog post page
    cont = document.getElementById("post-body");
    cont.insertAdjacentHTML("afterend", topP.outerHTML);
}

#6

Ah, yep, looks like it was an issue with how we were storing Javascript in the database. This is fixed – if you re-save the JS just like that it should work now :slight_smile:


#7

It worked fine, thanks a lot! :slight_smile: