有没有一种方法可以在我的nwjs应用程序中修改网站javascript/css,就像我们对Tampermonkey或Greasemonkey所做的那样?我做了一个Chrome扩展,它使用content_scripts部分,以便在某个网页加载时运行javascript,但我找不到在NodeJS中使用nwjs的方法。
当最终用户加载某个页面时,我需要运行几行代码,以便修改内容以匹配我的应用程序窗口和内容。
发布于 2015-07-06 15:22:16
check.html
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Test</title>
</head>
<body>
<iframe id="tgt" src="http://google.com/" style="position:fixed; left:0; right:0; width:100%; top:0; bottom:0;height:100%;" nwdisable nwfaketop>
</iframe>
<script src="check.js">
</script>
</body>
</html>check.js
var tgt = document.getElementById('tgt');
tgt.addEventListener('load', function () {
var dom = tgt.contentDocument,
script = document.createElement('script');
script.innerHTML = 'alert(window.location);'
dom.body.appendChild(script);
}main.js
// nothing in here for this testpackage.json
{
"name": "Check",
"main": "check.html",
"node-main": "main.js",
"window": {
"width": 1440,
"height": 900,
"position": "center",
"toolbar": true,
"title": "Do things now ...",
"resizable": true
}
}这将在google.com中成功插入和运行alert(window.location);
https://stackoverflow.com/questions/31239752
复制相似问题