Connecting client to server using Socket.io

I'm relatively new to node.js and it's addons, so this is probably a beginnersquestion. I'm trying to get a simple HTML page on a webserver connect to a different server running node.js with websocket.io. My code looks like this: Client <script src="socket.io/socket.io.js"></script> <script> // Create SocketIO instance, connect var socket = new io.Soc

使用Socket.io将客户端连接到服务器

我对node.js比较陌生,它是插件,所以这可能是一个初学者问题。 我试图在web服务器上获得一个简单的HTML页面,并通过websocket.io连接到运行node.js的其他服务器。 我的代码如下所示: 客户 <script src="socket.io/socket.io.js"></script> <script> // Create SocketIO instance, connect var socket = new io.Socket(); socket.connect('http://127.0.0.1:8080'); // Add a conn

Chrome, get selected text issue

I have made an extension for chrome that relies on getting the selected text of a page. Thanks to some of the questions on here, I have managed to do this but it seems to be spotty, only working on 'most' pages. Any ideas why: sendResponse({data: window.getSelection().toString()}); in my selection.js only works on some sites and does not work on, for example: http://www.tdwg.org/

Chrome,获取选定的文本问题

我对chrome进行了扩展,它依靠获取页面的选定文本。 由于这里提到的一些问题,我设法做到了这一点,但似乎很少见,只能在“大多数”页面上工作。 任何想法为什么: sendResponse({data: window.getSelection().toString()}); 在我的selection.js只适用于某些网站,并不起作用,例如: http://www.tdwg.org/? 它只是与页面结构有关,不值得处理? 编辑:我可以明确地将问题隔离到此代码中,因为调用此简单代码抓取所选

Firefox XUL toolbar problem with javascript getElementById

I'm writing my first Firefox XUL toolbar, and am getting a strange behavior - in order to debug my code, I call the same js function from both the firefox toolbar and from a button on a very simple HTML file I created. The javascript function displays an alert window, gets an element using 'document.getElementById', changes its color, and displays another alert window. The javascr

使用javascript getElementById的Firefox XUL工具栏问题

我正在编写我的第一个Firefox XUL工具栏,并且出现了一个奇怪的行为 - 为了调试我的代码,我从firefox工具栏和我创建的非常简单的HTML文件上的按钮调用了相同的js函数。 javascript函数显示警告窗口,使用'document.getElementById'获取元素,更改其颜色,并显示另一个警报窗口。 当使用HTML按钮进行调用时,javascript函数运行良好,但使用工具栏按钮时,'document.getElementById'返回null并且函数终止(

Feature detect if user gesture is needed

is there a way to detect if calling play() on a video element is allowed without a user gesture? On Android Chrome this warning is given: Failed to execute 'play' on 'HTMLMediaElement': API can only be initiated by a user gesture. So on Chrome Android a user gesture is required to start the playback of a video, while it isn't on desktop Chrome. Is there a way to detect w

特征检测是否需要用户手势

有没有一种方法来检测是否允许在视频元素上调用play()而无需用户手势? 在Android Chrome浏览器中会发出以下警告: Failed to execute 'play' on 'HTMLMediaElement': API can only be initiated by a user gesture. 因此,在Chrome Android上,需要用户手势才能开始播放视频,而不是在桌面版Chrome上。 有没有办法来检测我会得到哪些行为? 我想在我的应用程序中具有稍微不同的行为,具体取决于是否允

jquery escape square brackets to select element

Consider a input element <input id="meta[152][value]" type="text" /> Here the input field is dynamically generated. I need to select that field. So I used, alert($('#meta[152][value]').val()); But this seems to be invalid. After searching I found, that the "square brackets" need to be escaped like #meta\[152\]\[value\] So how to do that ? I currently use this code, var

jquery转义方括号来选择元素

考虑一个输入元素 <input id="meta[152][value]" type="text" /> 这里输入字段是动态生成的。 我需要选择该字段。 所以我用了, alert($('#meta[152][value]').val()); 但这似乎是无效的。 搜索后,我发现,“方括号”需要像#meta\[152\]\[value\] 那么该怎么做? 我目前使用这个代码, var id = "#meta[152][value]" // (I get this value by another method) I need the escaping to be done here. So that i ca

What is the difference between properties and attributes in HTML?

After the changes made in jQuery 1.6.1, I have been trying to define the difference between properties and attributes in HTML. Looking at the list on the jQuery 1.6.1 release notes (near the bottom), it seems one can classify HTML properties and attributes as follows: Properties: All which either has a boolean value or that is UA calculated such as selectedIndex. Attributes: 'Attributes

HTML中属性和属性有什么区别?

在jQuery 1.6.1所做的更改之后,我一直试图在HTML中定义属性和属性之间的区别。 查看jQuery 1.6.1发行说明(接近底部)的列表,似乎可以按如下方式对HTML属性和属性进行分类: 属性:所有具有布尔值或UA计算的值,例如selectedIndex。 属性:可以添加到既不是布尔值也不包含UA生成值的HTML元素的'属性'。 思考? 在编写HTML源代码时,您可以在HTML元素上定义属性。 然后,一旦浏览器解析你的代码,就会创建一

can one include `templates` in a html file similar to css?

working with html templates . code-wise, it's difficult to keep the right set of templates with each html file. is it possible to have a file of template(s), much like a file of css , that one includes in the head section of the html file? for example, to supplement the style section in head , one can link to a stylesheet, eg, <link rel="stylesheet" type="text/css" href="mystyle.css

可以在类似于CSS的html文件中包含`templates`吗?

使用html templates 。 在代码方面,很难为每个html文件保留一组正确的模板。 是否有可能有一个模板文件,很像一个css文件,它包含在html文件的head部分? 例如,为了补充head的style部分,可以链接到样式表,例如, <link rel="stylesheet" type="text/css" href="mystyle.css" > 我的应用程序使用几个templates集合。 可以像样式表一样处理它们,即链接到单独的文件中,还是每个template定义都需要直接作为原始

Where to place JavaScript in an HTML file?

Say I have a fairly hefty JavaScript file, packed down to roughly 100kb or so. By file I mean it's an external file that would be linked in via <script src="..."> , not pasted into the HTML itself. Where's the best place to put this in the HTML? <html> <head> <!-- here? --> <link rel="stylesheet" href="stylez.css" type="text/css" />

将JavaScript放在HTML文件中的位置?

假设我有一个相当大的JavaScript文件,压缩到大约100kb左右。 通过文件我的意思是这是一个外部文件,它将通过<script src="...">链接进来,而不是粘贴到HTML本身。 哪里是最好的地方把它放在HTML中? <html> <head> <!-- here? --> <link rel="stylesheet" href="stylez.css" type="text/css" /> <!-- here? --> </head> <body> <!-- here? --

pages create by repeat

I try to use swipe-pages by template repeat. <swipe-pages> <template is="dom-repeat" items="{{values}}"> <swipe-page> <div> Text to swipe </div> </swipe-page> </template> </swipe-pages> In the polymer I wrote created: function() { console.log(this

重复创建页面

我尝试通过模板重复使用滑动页面。 <swipe-pages> <template is="dom-repeat" items="{{values}}"> <swipe-page> <div> Text to swipe </div> </swipe-page> </template> </swipe-pages> 在我写的聚合物中 created: function() { console.log(this); this.va

Determine OS newline in JavaScript

I am generating a file for the user to download, and I want to insert the correct newline character(s) for their platform ( n , r , or rn ). I am aware of the following solutions, but none solve my problem exactly: Querying navigator.platform or navigator.appVersion . These properties are deprecated, so I would prefer not to rely on them. There are specific approaches for Firefox and NodeJ

在JavaScript中确定OS换行符

我正在生成供用户下载的文件,并且我想为他们的平台插入正确的换行符( n , r或rn )。 我知道以下解决方案,但没有一个完全解决我的问题: 查询navigator.platform或navigator.appVersion 。 这些属性已被弃用,所以我不想依赖它们。 Firefox和NodeJS有特定的方法。 这些不适用,因为我正在创建一个网站,而且我更喜欢它是否适用于所有浏览器。 有许多方法可以找到浏览器的换行符,但我对用户的平台很感兴趣。 (这