0

I'm trying to open an HTML/CSS/JS file in a browser with python.

No problem here, i'm sending an URL and everything is okay but when I want to add parameters to my URL like this : file:///C:/Users/Me/Desktop/pageHTML.html?x=38

Every browser will open it like this : file:///C:/Users/Me/Desktop/pageHTML.html

I read that Windows was doing it for strange security issues

So I was wondering if someone had a solution in Python or maybe in JS to this problem ?

Unfortunatly, I cannot read it with a local server, this has to be a local file.

1 Answers1

0

OK I found a way, this post already answer the question in java,but i think that I can answer for the newby like me that have problems with translating a langage to another.

So here is the code :

import tempfile
import webbrowser

def createRedirectPage(url):
    return("<!DOCTYPE HTML>" +
            "<meta charset=\"UTF-8\">" +
            "<meta http-equiv=\"refresh\" content=\"1; url=" + url + "\">" +
            "<script>" +
            "window.location.href = \"" + url + "\"" +
            "</script>" +
            "<title>Page Redirection</title>" +
            "<!-- Note: don't tell people to `click` the link, just tell them that it is a link. -->" +
            "If you are not redirected automatically, follow the <a href='" + url + "'>link</a>")

def createRedirectTempFile(url):
    tmp=tempfile.NamedTemporaryFile(delete=False)
    path=tmp.name+'.html'

    f=open(path, 'w')
    f.write(createRedirectPage(url))
    f.close()
    webbrowser.open('file://' + path)

createRedirectPage("YourURL")