Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8636039
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 12, 20262026-06-12T10:07:34+00:00 2026-06-12T10:07:34+00:00

I have made a website where, upon choosing an item in the menu bar,

  • 0

I have made a website where, upon choosing an item in the menu bar, the screen moves to a specific spot on the page. I then made a function in which the text changes in two spots, “titletext” and “infotext”. Example:

<li><a href="#content" onclick='changeText()'>Weeee!</a></li>

It works but now I realize I have a problem: When I choose to go back to the previous page, the text remains the same, until the user chooses to refresh the page.

Using Javascript, how can I tell the website to change the text when (for example) the page is on #content and change the text again when it’s on the home page? Do I have to take a different approach with my code?

Below is my code for changeText():

function changeText(){
    document.getElementById('titletext').innerHTML = 'Mission Statement';
    document.getElementById('infotext').innerHTML = 'RANDOMTEXT';
}

EDIT: Here’s an example of what I want my website to do.

When the user hits the back button on the browser, the text changes to
the previous text. So if it shows “Hey” then it shows “Bye”, when the
user hits the browser’s back button, the code changes to “Hey”

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-12T10:07:36+00:00Added an answer on June 12, 2026 at 10:07 am

    Take a look at this jQuery plugin which allows you to listen to #hash change events. Basically, once you installed that plugin, you can have something like this:

    window.onhashchange = function() { //when the hash changes (the '#' part)
        var loc = window.location + ""; //get the current location (from the address bar)
        var curHash = loc.substr(loc.lastIndexOf("#")); //get what's after the '#'
        if(curHash == "#home") { //if it's #home
            //change text to whatever you want
        }
        else if(curHash == "#nav") { //else if it's #nav
            //similarly, change text appropriately
        }
        else if(curHash == "#content") {
            //change text, too
        }
    };
    

    Edit: Actually, the onhashchange is already supported in current versions of modern browsers. Use the same code above, but nevermind about the plugin.

    There might be a simpler way to do this; but I hope this helped!

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have made a website in ASP.NET 3.5 With C#.In the default page we
I have made a website using( Asp.net, c# ) and its content in English
I have made some screenshots of my website, and in internet explorer 6 my
I have made some screenshots of my website, and in internet explorer 6 my
I have an engineering website made in Visual Studio / VB / .NET 4.0.
I've made a website to go on App Engine, and have deployed it. I've
I have a website that I made and I am planning to redo it.
I have a contact form made with php on my website. The problem is
I have made a jQuery toggle for a menu that I had in mind.
I have made a website and put inside it a flash game. For people

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.