Is there a better way of handling button redirection to different page?

I have the following landing URL for a website:
https://mydevserver.com/Downloader/index.html

Inside index.html I have the following two buttons, from where I am taking user to different pages. Is there a better way of handling this? I mean if I deploy to different servers, like dev,test and prod, I will have to keep changing the URL everytime on my end.

<div class="btn-group-vertical">
<button type="button" class="btn btn-default" onclick="location.href='https://mydevserver.com/Downloader/fdb.html'">First Builder</button>
<button type="button" class="btn btn-default" onclick="location.href='https://mydevserver.com/Downloader/sdb.html'">Second Builder</button> 
</div>

Well typically what is done is that you have an environment variable set for your project that tells code what system it is on (like “dev”, “prod” or “test”) and then you can have the code look at its environment variable and build the URL accordingly. Sometimes this means just changing the domain portion of the URL or it might be the whole URL.

How you go about setting up this environment variable is up to the technologies you are using. Some projects use .env files (like Laravel) and others use some sort of config file that stores all the settings (like done in WordPress with the wp-config.php file).

What you do is typically set up this environment variable based on the server and then you can deploy the same code and it will adjust output based on the variable.

If you are using just javascript and HTML, maybe you can just have a stand alone JS file that contains your environment variables (like a simple JSON object) and import that in and so your javascript can then see it and act accordingly.

I hope you get the idea. :slight_smile:

1 Like

Ok, Thanks. I will try to implement something like that.

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