与Firefox innerText问题的Javascript [英] Javascript with Firefox innerText issue

查看:123
本文介绍了与Firefox innerText问题的Javascript的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 函数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 from textContent, 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屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆