-1

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.

7
  • Does this answer your question? Open a URL in a new tab (and not a new window). A website or new tab is always opened client-sided. The server just serves the files it does not open them themselves....
    – tacoshy
    Commented Nov 10, 2023 at 9:49
  • The context of your question is quite unclear. "where I have a button to click in that text is there" - are you talking about HTML that is shown to the user in the browser here - or something else? Because if it is the former, then you would simply put a link into that HTML - not sure why this would involve any processing of that "click" on the server side at all to begin with?
    – C3roe
    Commented Nov 10, 2023 at 9:50
  • It seems to me that you have a dev environment and a live environment. And your code works properly in your dev environment, but not on live. Is this an accurate description of your problem? Commented Nov 10, 2023 at 9:58
  • yes works in dev but not in prod
    – Charlie
    Commented Nov 10, 2023 at 10:09
  • @CBroe yes a button with a text is there in a chatbot ,so whenever a button is clicked (URL is embedded into it) it will open a URL in new tab.
    – Charlie
    Commented Nov 10, 2023 at 10:19

2 Answers 2

0

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'); });

0

assuming you mean the current computer web browser tab, (and on windows), you can do this:

import os
os.system("start <full URL here. can use f strings>")

or if it is a website you are hosting, you can use an HTML redirect:

<meta http-equiv="refresh" content="delay_time; URL=new_website_url" />
1
  • Thanks , none of us code working , it is opening on server side but not on client side
    – Charlie
    Commented Nov 14, 2023 at 11:50

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.