简体   繁体   English

使用node-webkit创建自定义Web界面应用程序并使用Javascript操作DOM

[英]creating custom web interface app using node-webkit and manipulating DOM with Javascript

I want to create a custom web interface/app to a web site. 我想创建一个自定义Web界面/网站的应用程序。 Basically a streamline/custom view of important summary data. 基本上是重要摘要数据的简化/自定义视图。 The data can be cached locally in the app and updated weekly if there are changes to the source site. 数据可以在应用程序本地缓存,并且如果源站点有更改,则每周更新一次。 I am using two windows. 我正在使用两个窗口。 One window I load the html from remote site, the second window I manipulate the DOM/tables of the first window using Javascript to only display information that is important. 我从一个远程站点加载html窗口,第二个窗口使用Javascript处理第一个窗口的DOM /表,以仅显示重要信息。 If there is a better way or tool to do this as I have not found it yet. 如果有更好的方法或工具来执行此操作,因为我尚未找到它。 I am having problems with Javascript not being able to manipulate the DOM of the first window. 我遇到Javascript无法处理第一个窗口的DOM的问题。

Im trying to edit/format the DOM (hide/delete table rows change colors) in the 2nd window from javascript running in the first window (startup node-webkit). 我试图从在第一个窗口(启动node-webkit)中运行的javascript编辑/格式化第二个窗口中的DOM(隐藏/删除表行更改颜色)。 Docs say that I should have universal access to the other windows? 文件说我应该可以通用访问其他窗口? How do I make sure this is true? 我如何确保这是真的?

var gui = require('nw.gui');
var new_win = gui.Window.get( window.open('http://example.com/index.html'));
var my_elem = new_win.document.getElementById('myelement');
my_elem.style.display='none';

Type Error: Cannot read property of 'getElementById' of undefined 类型错误:无法读取未定义的'getElementById'的属性

Any ideas? 有任何想法吗?

In order to access the document property of the new window you have to access it in the window key. 为了访问新窗口的文档属性,您必须在窗口键中访问它。

Basically change your line 3 to this: 基本上将第3行更改为:

var my_elem = new_win.window.document.getElementById('myelement');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM