python-eel / Eel

A little Python library for making simple Electron-like HTML/JS GUI apps
MIT License
6.44k stars 587 forks source link

Redirecting to a different page #394

Closed mechanikate closed 4 years ago

mechanikate commented 4 years ago

Describe the problem I'm trying to make my Eel application be able to have multiple pages and not just be one HTML file. How can I redirect the application to another HTML file?

Code snippet(s) Here is some code that can be easily used to reproduce the problem or understand what I need help with.

import eel

# Set web files folder
eel.init('web')

eel.start('file1.html')
... file 1:
<button onclick="window.location.href = 'file2.html'>file two</button>

... file 2:

<p>hello world!</p>

Desktop (please complete the following information):

samuelhwilliams commented 4 years ago

Your example works just fine, in principle, except you're missing a closing double-quote for the onclick attribute. It should be:

<button onclick="window.location.href = 'file2.html'">file two</button>

Though this is probably simpler as just a plain link:

<a href="/file2.html">file two</a>

Eel presents as a standard webserver using basic HTML/CSS/JS, so you don't need to do anything unusual to support moving between pages in your app.

mechanikate commented 4 years ago

That was just an example, and I need to have it in a JavaScript submit() function, and the window.location.href = 'file2.html' snippet does not work

mechanikate commented 4 years ago

Seems that adding one slash before the file2.html worked! Thanks for your help