How to pass variable value between different html pages in javascript

You can pass the value as a url fragment.

In your on click function, open ‘/profile.html#’+text

In your profile.html get the url fragment.

Sample code:

To navigate to profile.html

window.location.href="https://stackoverflow.com/questions/23213788/<path to profile.html>" + '#' + text;

In profile(), to get the parameter, use

var text = window.location.hash.substring(1)

Leave a Comment