I'm not sure what doesn't work since there is no specific problem that is posted but I'm guessing it's the window.open()?
I found this article
window.open(url, '_blank'); not working on iMac/Safari
it might be the one you were looking for.
From:
Kelly J Andrews
The standard window.open() JavaScript method cannot be used to open a new tab and window from a global HTML file or an extension bar. Instead, the global file and extension bars have access to the SafariApplication, SafariBrowserWindow, and SafariBrowserTab classes, whose methods and properties allow you to work with windows and tabs.
It goes on to explain how you can use
var newTab = safari.self.browserWindow.openTab();