与Firefox innerText问题的Javascript [英] Javascript with Firefox innerText issue
问题描述
函数OpenWindow(anchor){
,因为第一个被操作的方式漂亮的印刷(例如,
var toUsername = anchor.innerText;
window.open(ChatWindow.aspx?username =+ toUsername,'_ blank',width = 340,height = 200);
$ b $ p
$ b这个函数打开一个页面,镀铬我得到应有的价值。
Firefox的URL:
的的http://本地主机:9452 / ChatWindow.aspx用户名=未定义
什么是这个问题的解决方法
解决方案虽然
的innerText
是非标准的,它显著从<$ C $不同C>的textContent<峰; br />
被转换到了新的一行),而第二个 - 不是。
因此,虽然常见的智慧是使用:
var toUsername = anchor.innerText || anchor.textContent;
或某种包装的,大概可以更聪明,只是使用jQuery的
.text
或者你正在使用的其他库的模拟。function OpenWindow(anchor) { var toUsername = anchor.innerText; window.open("ChatWindow.aspx?username=" + toUsername,'_blank', "width=340,height=200"); }
this function opens up a page with parameter as undefined in firefox where as in google chrome I get proper value.
Firefox url: http://localhost:9452/ChatWindow.aspx?username=undefined
What is the solution for this issue?
解决方案While
innerText
is non-standard, it significantly differs fromtextContent
, because first one is doing pretty printing (for example,<br/>
are converted to new lines), while second one - is not.So, while common wisdom is to use:
var toUsername = anchor.innerText || anchor.textContent;
or some kind of wrapper, it can probably be smarter to just use jQuery's
.text
or its analog from other library you are using.这篇关于与Firefox innerText问题的Javascript的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!