问题
atom-shell only has a method to load HTML from a URL
window.loadUrl('file://...')
But I want to use Jade
var html = jade.renderFile('file://...');
Is there a way to use the compiled html
in atom-shell window
? Something like loadHtml(html)
?
I suppose I could run an express server that serves compiled html but that would be rather inefficient..
回答1:
In case of a mac:
/usr/bin/open -a "/Applications/Google Chrome.app" --args 'data:text/html,<html><body><h1>title</h1><p>text</p></body></html>'
Details about URI
https://developer.mozilla.org/en-US/docs/Web/HTTP/data_URIs
回答2:
An alternative is to use the executeJavaScript function with something like
mainWindow.loadUrl('about:blank');
var s = '<DOCTYPE html><html><head><title>Written!</title></head><body><h1>Hello!</h1></body></html>';
mainWindow.webContents.executeJavaScript('document.write("' + s + '");');
来源:https://stackoverflow.com/questions/27738823/loadhtml-instead-of-loadurl-in-atom-shell-trying-to-use-jade