This is as days pass by, by Stuart Langridge

And this is Firefox and the Python webbrowser module, written , and concerning Uncategorized

I’d like to be able to open a window without browser chrome from the Python webbrowser module. After a bit of poking around, it seems to be possible. This will only work with Mozilla, and it might only work on Linux (although it should be OK on Windows). The complexity in doing it is that you can’t specify a window size or configuration when calling webbrowser.open(). However, JavaScript can: the window.open() function can specify no-chrome, window sizes, the lot. But you can’t just call webbrowser.open('javascript:window.open("...")'), because then you’ll have two windows; the one that ran the JS and the one the JS opened. JS can’t close the one that ran the JS, because it wasn’t opened by JS. The solution? Chrome windows:

import webbrowser
moz = webbrowser.get('mozilla')
moz.open('javascript:void(window.open("http://www.kryogenix.org","winname","chrome"))')

It should be possible to make this work for IE as well, because IE allows a child window to close its parent, even if the parent wasn’t opened by JS. However, I don’t need that at the moment; if I ever release this app that I’m using this for (it’s an example of Browser as Desktop UI) then I’ll make it cross-browser.

-----

Comments

Janet

Maybe I'm missing something totally obvious, but this code still gives me two browser windows -- one with chrome opened by webbrowser.open, and one without chrome, opened by window.open.

I am using Mozilla 1.4.3, RHE Linux 3, and Python 2.3.

What's the missing link?

sil

Janet: hm, doesn't seem to work any more. It was a while ago I wrote this...

Janet

Thanks for checking. I wish it was just me being dense.

I suspect that what has changed is Mozilla's behavior.

Web Browser

Pretty nice find! Never tried it though! Python is good

This website belongs to Stuart Langridge. Contact details are available. Don't eat yellow snow. Valid HTML5, at least in theory, except for the bits that aren't because I'm that futuristic that I'm ahead of the spec, oh yes. HTML5 help from Bruce Lawson, among others. Fonts from the superb FontSquirrel. End.