NB: I didn;t run Paul's code, but it looks like you'd want to escape str. An effective 90% solution is to replace ' ' with '+'. I imagine that whatever package browse-url came from already has exactly such a function.