loadHtml instead of loadUrl in atom-shell? (trying to use jade)

落爺英雄遲暮 提交于 2019-12-24 02:44:35

问题


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

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!