Call a JavaScript Function from Flask
One way to do this is by passing the url as a query string to the url containing the javascript. You can acces the query string in javascript and use it in the function that opens the window.
I have a basic Flask app running, with the code in main.py hosting the flask app. I also have an index.html file that will get text input from the user. I can use request.form to access the input, and I can work with it successfully. However, I encountered a problem.
I need to call a JavaScript function that opens a new tab with a certain website. For example, if the user types in Wikipedia, I need to tell JavaScript to window.open("https://www.wikipedia.org"). The problem is, I can't find any working way to call a JavaScript function from a Flask application.
And before you mark this question as duplicate, the answer to the one Stack Overflow question on this I found did not even involve flask, and the other answer (using webbrowser.open_new_tab) opened the new tab on the server machine, not on the client machine (the one where the website is actually being accessed).
I know you can call a Python function from JavaScript, but is it possible to do it the other way?
Thank You in advance.