hope you are well, I am working on a project where I have a button to click in that text is there, so when I click that button, the URL should open in a new tab in the client machine but it is opening on the server side where the code is deployed, Please try to give a solution so that I can open a URL in next tab on client machine only.
Problem Statement:
Goal: Open a URL in a new tab on the client machine when a button is clicked.
Current Issue: The URL is opening on the server side where the code is deployed, not on the client side.
When in run in local environment then it is properly running where for html file i run a apache and using localhost:8080 working as expected.When i change url to domainname and deployed on server it is not working in client side but opening in serving browser.
I have tried several method including below code which is opening URL on the server side.
import web browser #library to open url in browser
if user_query.lower() == "click here": # when user query is click here
url = "http://domainname/MyApp/file.html" #it should open this url in client side only
webbrowser.open(url)
I have change in html code ,subprocess ,paromik and flask also so that redirection works ,but it is not working as expected.
2
Answers
You can use "a" tag, design it as a button and add there "_blank" attribute to specify redirection
or if you absolutely want to use button tag, js can make redirection :
const button = document.querySelector(‘#myButton’);
button.addEventListener(‘click’, function() { window.open(‘https://www.yourlink.com’, ‘_blank’);
});
assuming you mean the current computer web browser tab, (and on windows), you can do this:
or if it is a website you are hosting, you can use an HTML redirect: