开发者

How can I tell Chrome or Firefox to run Javascript or load a Bookmarklet from the commandline?

Is it possible to, from the command line, tell Chrome or Firefox to run javascript i开发者_StackOverflow社区n the currently open browser window? Or alternatively, load a bookmarklet that contains javascript?

I'd like to have a program that watches for changes to a css file, and when the css file updates, the browser window would automatically load the new css file. I've setup a javascript bookmarklet to do this, but I'd love to have it done automatically whenever the css file updates.


In Firefox this definitely won't be possible without an extension, don't know about Chrome. The command line can open a javascript: URL but this code will run in its own tab, without access to the page you are currently viewing. So an extension would need to implement nsICommandLineHandler interface (see https://developer.mozilla.org/en/Chrome/Command_Line for an example) and handle some command line flag. It would then use nsIWindowWatcher.getMostRecentWindow("navigator:browser") to get the current browser window and do window.gBrowser.contentWindow.location.href = "javascript:..." to run the bookmarklet on the current tab.


For FF: The source code to this may help: https://addons.mozilla.org/en-US/firefox/addon/css-refresh-199425/

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜