Showing posts with label Firefox. Show all posts
Showing posts with label Firefox. Show all posts

Thursday, January 13, 2011

springmvc 中ajax提交发生乱码问题

这个问题目前只是在springmvc项目中碰到,在IE和Chrome中,当用jQuery.post()方法发起ajax请求时,Controller中收到的中文内容变成乱码了,而在firefox中用jQuery.post()进行ajax请求时是正常的。
在Controller中调用如下代码(项目为UTF-8编码):


// name 是post收到的字符串变量名
System.out.println(new String(name.getBytes(HTTP.ISO_8859_1), HTTP.UTF_8));

可以看到乱码恢复正常,说明IE和Chrome提交的ajax请求中的内容被编码成 ISO-8859-1 编码了。
而实际上,对于IE而已,所有的ajax请求都是以UTF-8方式发起的,通过以下方式设置ajax请求的编码为GBK实际是没有用的,服务器收到仍然是UTF-8编码的请求体:

xmlhttp.setRequestHeader( "Content-Type", "text/html;charset=GBK" );
// or
xmlhttp.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded; charset=GBK");

因此可以肯定是springmvc在收到POST请求后,将请求体的数据用 ISO-8859-1 编码来处理了,最后传到Controller中时变成了乱码,但是为何firefox中提交的却仍然是正确的呢?
在firebug中观察firefox中的ajax请求头,可以看到firebug中的提示:

Content-Type application/x-www-form-urlencoded; charset=UTF-8

而在IE中用http analysis工具看到的却是:

Content-Type application/x-www-form-urlencoded

google Chrome中与IE一样,ajax请求头中没有指明编码,所以Chrome和IE一样将发生乱码了。
查看jquery-1.4.4.js源码可以看到,jQuery中原来的 contentType设置为"application/x-www-form-urlencoded",IE和Chrome中的请求头显示是正确的,没有问题,反而是firefox将contentType中设置了编码。
从这个请求头分析来看,应该是springmvc没有得到请求的编码,而将其内容设置为ISO-8859-1了,因此发生了乱码的情况。

解决方法还是参考firefox的请求头,在contentType中指定编码,明确告诉服务器端,当前请求体的编码方式为UTF-8。

xmlhttp.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded; charset=UTF-8");

如果使用jQuery发起ajax请求,javascript的代码改为如下方式发起ajax请求,而不是以$.post()和$.get()等快捷方法:

$.ajax({
url: url,
type: "POST",
dataType: "html",
contentType: "application/x-www-form-urlencoded; charset=UTF-8",
data: data,
complete:function(data) {
}
});

Sunday, December 19, 2010

comments bug on firefox


<body>
<!--

这段HTML注释代码因为中间多了2个连字符,在firefox中会导致解析出错,这段内容被做为正常的文本内容显示在浏览器中。
This entire comment -- will show in web browser

-->
</body>

Reference: (SGMLComment) Mozilla interprets a -- (two dashes in a row) inside of a comment or an include improperly

Friday, November 05, 2010

get Xpath of html element

在Firefox中有二个非常有用的插件,可以直接得到HTML页面中元素的XPath:

XPath Checker - suggests XPath and can be used to test XPath results.
Firebug - XPath suggestions are just one of the many powerful features of this very useful add-on.

XPath的参考资料:

W3Schools XPath Tutorial
W3C XPath Recommendation
XPath Tutorial - with interactive examples

Sunday, July 12, 2009

iframe src problem in firefox

<iframe src='javascript:'></iframe>
在firefox下,当运行到上面语句的时候,将会弹出错误控制台。

Monday, January 19, 2009

Remove gmail Sponsored link in firefox3

under ubuntu8.10, goto user profile directory and create dir "chrome" if "chrome" is not exists.
$> cd ~/.mozilla/firefox/user*profile.default/chrome
$> vi userContent.css

/*
* For remove gmail ad links
*/
.eWTfhb div[class="XoqCub"][style="width: 225px;"]{
height:0px!important;overflow:hidden!important;width:0px!important;
}
.tELAdc div[class="XoqCub"][style="width: 225px;"]{
height:0px!important;overflow:hidden!important;width:0px!important;
}
div.qWFFaf {
display:none!important;
}
restart firefox.
in other OS, userContent.css may in below path:
Windows 2000/XP
C:\Documents and Settings\[USER]\Application Data\Mozilla\Firefox\Profiles\*.default\chrome\
Mac OS X
~/Library/Application Support/Firefox/Profiles/[profile-name]/chrome/

Tuesday, December 23, 2008

ie中空白渲染的问题

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
</head>
<body>
<form action="test_submit" method="get" accept-charset="utf-8">
<input type="text" name="some_name" value="" id="name">
<div id="x" style="white-space:pre;">x xx x</div>
<div id="y">y yy y</div>
<p><input type="button" value="click here" onclick="document.getElementById('name').value=document.getElementById('x').innerHTML"></p>
<p><input type="button" value="click here" onclick="document.getElementById('name').value=document.getElementById('y').innerHTML"></p>
</form>
</body>
</html>

上面的例子在ie6/ie7中测试时可发现y组成的字符串,其中的空格被ie渲染过后,取到的innerHTML已经变为一个空格了,在firefox/safari上在渲染后看上去是只有一个空格,但innerHTML取到的还是与原码是保持一致的。

Sunday, October 05, 2008

Firebug command line api 和 console api 中比较常用到的几个方法

1. $(id) 与 prototype 用法类似,只能传字符串的Element Id。
2. $$(selector) 与 prototype 用法类似,传一个CSS Selector字符串,另专门还有一个$x("xPath")方法接受xpath方式查询DOM节点。
3. dir(object) 遍历object所有属性,在console中打印出来。
4. clear() 清空console。
5. debug(fn) 在对应的fn方法第一行加一个断点,当此方法调用时就会进入此方法第一行,可进行断点调试此方法。对应的有undebug(fn)取消断点。

6. console.log(object[, object, ...]),console是Firebug在Firefox中添加的一个全局变量名。其log()方法会将对象打印到firebug控制台中,支持类似printf()的功能。
7. 同console.log()类似的还有console.debug(),console.info(),console.warn(),console.error()方法。
8. console.assert(expression[, object, ...])断言功能,用来检查表达式是否正确执行。

Reference: http://getfirebug.com/commandline.html
http://getfirebug.com/console.html

Sunday, August 17, 2008

AutoCompleter from local based on Prototype


<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
<head>
<title>completer demo</title>
<meta http-equiv="content-type" content="text/html; charset=utf-8" />
<script src="/lib/prototype.js" type="text/javascript"></script>
<style type="text/css">
body {
font: 11px Lucida Grande, Verdana, Arial, Helvetica, sans serif;
}
</style>
</head>
<body>
<br/>
<div id="content">
<form>
input "a" for test:
<input id="message" name="message" size="30" type="text" />
<input type="submit" value="submit"/>
</form>
<script type="text/javascript">
//<![CDATA[
var contacts = ["aa", "aaa", "aaaa", "abb", "abbb", "ac", "acc", "accc", "aac", "aaac", "bc", "ad", "aad", "aaad", "aaaad", "aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa", "中文字体", "测试~!@#$%^&*()/?\"\\';", "北京奥运会", "姚明&刘翔"];

AutoFieldFromLocal = Class.create({
initialize: function(element, items){
this.element = $(element);
this.value = this.element.value;
this.items = items;
this.timer = null;
this.observer = null;
this.counter = 0;
this.index = 0;
this.listElements = [];
this.listsObserved = false;
this.maskShowed = false;
this.divId = "auto_complete_for_" + this.element.id;
this.listsId = "lists_of_" + this.element.id;
this.maskId = "mask_" + this.element.id;
this.element.setAttribute('autocomplete', 'off');
this.insertAfter();
this.observerStart();
},
insertAfter: function(){
new Insertion.After(this.element,
'<div id="' + this.divId + '" style="position:absolute;background-color:#fff;border:1px solid #888;margin:0;padding:0;display:none;height:200px;opacity:0.90;overflow:auto;overflow-x:hidden;z-index:1;filter:alpha(opacity=90);">' +
'<ul id="' + this.listsId + '" style="margin:0;padding:0;list-style-type: none;width:100%;"></ul></div>' +
'<div id="' + this.maskId + '" style="position:absolute;background-color:blue;border:1px solid #888;margin:0;padding:0;display:none;height:0;opacity:0;z-index:2;filter:alpha(opacity=0);"/>'
);
this.completerDiv = $(this.divId);
this.list = $(this.listsId);
this.mask = $(this.maskId);
},
observerStart: function(){
// safari/ie中监听keypress时,arrow keys箭头无法正确激活绑定的事件,改用keydown监听
// Arrow keys no longer result in keypress events, now processed in keydown default event handler
// Reference: https://lists.webkit.org/pipermail/webkit-dev/2007-December/002992.html
// keydown/keypress区别参考ppk的文章: http://www.quirksmode.org/dom/events/keys.html
if (Prototype.Browser.WebKit || Prototype.Browser.IE) Event.observe(this.element, 'keydown', this.renderLists.bindAsEventListener(this));
else Event.observe(this.element, 'keypress', this.renderLists.bindAsEventListener(this));
Event.observe(this.element, 'blur', this.onBlured.bindAsEventListener(this));
Event.observe(document, 'mousemove', this.hideMask.bindAsEventListener(this));
},
addListsObserver: function(){
var self = this;
this.listElements.each(function(li){
Event.observe(li, 'mouseover', self.onMouseOverList.bindAsEventListener(self));
Event.observe(li, 'click', self.updateField.bindAsEventListener(self));
});
this.hideMask();
},
hideMask: function() {
if (this.maskShowed) {
this.maskShowed = false;
this.mask.style.height = '0px';
this.mask.style.display = "none";
}
},
showMask: function(){
if (!this.maskShowed) {
this.maskShowed = true;
this.mask.style.height = this.completerDiv.clientHeight + 'px';
this.mask.style.display = "block";
}
},
onBlured: function(){
var self = this;
if (this.timer) clearTimeout(this.timer);
this.timer = setTimeout(function(){
self.hideMask();
self.completerDiv.hide();
}, 100);
},
updateField: function(){
this.element.focus();
if(this.listElements.length > 0 && this.index != -1)
this.element.value = this.listElements[this.index].innerHTML.replace(/&/, "&");
this.completerDiv.hide();
this.hideMask();
},
listsShowed: function(){
return this.completerDiv.style.display.toLowerCase() == 'block';
},
onSelectList: function(){
this.listElements.each(function(li){
li.style.backgroundColor = "#fff";
});
this.listElements[this.index].style.backgroundColor = "#ffb";
},
divScrollTop: function() {
var maxScrollTop = this.completerDiv.scrollHeight - this.completerDiv.clientHeight;
var scrollBottom = this.completerDiv.clientHeight + this.completerDiv.scrollTop;
var listHeight = this.listElements[0] ? this.listElements[0].clientHeight : 20;
// TODO , get li.clientHeight after insert li element and then remove it if ul list has no li child.
if (this.index == 0)
this.completerDiv.scrollTop = 0;
else if (this.index == this.listElements.length - 1)
this.completerDiv.scrollTop = maxScrollTop;
else if (this.index * listHeight < this.completerDiv.scrollTop)
this.completerDiv.scrollTop = this.index * listHeight;
else if (this.index * listHeight >= scrollBottom)
this.completerDiv.scrollTop = this.completerDiv.scrollTop + listHeight;
},
markNextList: function(){
this.showMask();
if(this.index < this.counter - 1) this.index++
else this.index = 0;
this.divScrollTop();
this.onSelectList();
},
markPrevList: function(){
this.showMask();
if(this.index > 0 ) this.index--
else this.index = this.counter - 1;
this.divScrollTop();
this.onSelectList();
},
onMouseOverList: function(event){
var elementLI = Event.findElement(event, 'LI');
this.index = this.listElements.indexOf(elementLI);
this.listElements.each(function(li){
li.style.backgroundColor = "#fff";
});
elementLI.style.backgroundColor = "#ffb";
// this.divScrollTop();
},
renderLists: function(event){
switch(event.keyCode) {
case Event.KEY_LEFT:
case Event.KEY_RIGHT:
return;
case Event.KEY_ESC:
this.completerDiv.hide();
this.hideMask();
// esc will also empty input field in ie by default, prevent default event.
Event.stop(event);
this.index = -1;
return;
case Event.KEY_TAB:
case Event.KEY_RETURN:
this.updateField();
Event.stop(event);
return;
case Event.KEY_DOWN:
if (this.listsShowed()) {
this.markNextList();
return;
}
case Event.KEY_UP:
if (this.listsShowed()) {
this.markPrevList();
return;
}
}
if (this.observer) clearTimeout(this.observer);
var self = this;
this.observer = setTimeout(function(){self.onFieldChange(event)}, 100);
},
onFieldChange: function(event){
var value = this.element.value.strip();
var autoWidth = this.element.getWidth();
var find = false;
var listItems = "";
this.counter = 0;
this.index = -1;
var self = this;
if (Prototype.Browser.IE || this.value != value || event.keyCode == Event.KEY_DOWN) {
this.value = value;
this.items.each(function(item){
if (item.include(self.value)) {
self.counter ++;
// li element defaults line-height is different in different browser:
// safari 13px, firefox3 14px
// li width must be set 100% and display block for ie, and ie scrollbar movement has related with li width, sign...
// font size should be little than 14px in ie
listItems += "<li style='line-height:14px;padding:3px;margin:0;display:block;width:100%;cursor:default;'>" + item + "</li>";
if (!find) find = true;
}
});
}
if (find) {
this.list.innerHTML = listItems;
var pos = Position.cumulativeOffset(this.element);
this.completerDiv.style.width = this.mask.style.width = (autoWidth - 2) + "px";
this.completerDiv.style.left = this.mask.style.left = pos[0] + "px";
this.completerDiv.style.top = this.mask.style.top = (pos[1] + this.element.getHeight() - 1) + "px";
this.completerDiv.style.display = "block";
this.listElements = this.list.childElements();
this.addListsObserver();
} else {
this.completerDiv.hide();
this.hideMask();
}
}
});

var af = new AutoFieldFromLocal('message', contacts);
//]]>
</script>
</div>

</body>
</html>

需要注意一下以下几点:
1、在safari/ie中对于arrow keys事件的处理方式和keydown/keypress二者区别。
2、在ie中esc默认行为会将input框中的值一起cancel。
3、在firefox中mouseover事件的控制,在用arrow keys移动选项时,用一个蒙板挡住了mouse,以防触发mouseover事件。
4、setTimeout()方法中的this需要小心其指向全局的window。
5、当y轴出现滚动条时,其实际可以滚动的长度不是element.scrollHeight,而应该是此值减去element.clientHeight。
6、IE中控制滚动条用overflow:auto; overflow-x:hidden;
7、IE中滚动条和LI元素的宽度有关系,要控制滚动条则需要设置LI宽度为100%。
8、对&作特殊处理。

Tuesday, July 29, 2008

firefox clear private data shortcut

apple + shift + delete

Tuesday, July 22, 2008

firefox3 中tab键无法focus到select控件

解决方法: 在system preference-keyword&mouse-keyword shortcuts中选中all controls.
也可直接用快捷键ctrl+F7进行切换。

Friday, July 18, 2008

firefox 禁止javascipt移动或改变窗口大小

工具-选项-内容-允许JavaScript-高级,取消“移动或改变窗口大小”。
    
或者
about:config
dom.disable_window_move_resize
双击该变值为true
Reference: http://www.douban.com/group/topic/3721646/

Wednesday, July 16, 2008

firefox undo closed tab shortcut

ctrl + shift + t: 打开最后关闭的tab

Wednesday, June 11, 2008

关闭firefox工具条的提示

在拖动某个网页保存为书签时,firefox总是会在工具条上提示:
Drag and drop this icon to create a link to this page
这个很影响操作,可以通过firefox的about:config进行设置:
1. 在地址栏输入: about:config 回车
2. 输入tips,找到browser.chrome.toolbar_tips,修改值为false即可。

Wednesday, May 28, 2008

firefox addons for web developer

强力推荐 firefox addons: web developer/firefbug/HttpFox



2008下载日

Sunday, May 25, 2008

MacBook 中 FIREFOX2 中文网页乱码及掉字问题解决方法

中文乱码主要原因是因为安装了OFFICE 2008对SIMSUN字体产生冲突,FIREFOX 3就没有这个问题。
FIREFOX 2下的解决方法就是在FONT BOOK中把SIMSUN这个字体先禁用掉。如果按下面修改了2个自定义的css文件,指定firefox的渲染字体,那么就不需要去禁用SIMSUN字体了。
可以打开http://www.163.com看一下是否正常。

在 firefox2 中还有一个就是在input框中输入的中文掉字和光标错位的问题,比如在google搜索框里输入"暂停删除"这四个字就可看得到。
这个需要修改一下 firefox2 的渲染css文件:
默认的目录是 ~/Library/Application Support/Firefox/Profiles/xxxxxxxx.default/chrome/
下面原来有2个example.css文件,对应的生成userChrome.css 和 userContent.css 这2个文件,并在这二个文件中都加入一个css定义:


* {
font-family: Lucida Grande, 华文黑体;
}

需要注意的是,一定要把文件保存为 UTF-8 格式。Lucida Grande 和华文黑体,都是苹果的默认字体,也是 Safari 默认字体。

Reference: http://www.wpdr.net/forums/showthread.php?t=3287
http://hi.baidu.com/dawgdash/blog/item/6157a138c501b227b8998ff1.html

Thursday, April 17, 2008

img的onload事件说明


<script type="text/javascript">
function test() {alert('test');}
</script>
<img src="a.png" onload="test()" />

当img的src指向的a.png不是一个实际的png文件,比如是个空文本文件名为a.png(文件大小为0字节),此时就不会触发onload事件,实际发生的此img.onerror事件。
如果往此文件中写入一个字符,使文件大小大于0字节,此时在Firefox中能触发onload事件,在IE中则因为图片加载不正常,会在页面上显示一个加载图片失败的X图形,并触发的是onerror事件。

还原apache访问日志中的URL查询字符串

当IE在访问URL:
http://localhost/a.html?q=中文
在apache日志里能看到以下内容:
GET /a.html?q=\xd6\xd0\xce\xc4 HTTP/1.1

而在Firefox中访问相同URL:
日志中看到的内容是对字符串进行urlencode过后的格式:
GET /a.html?q=%D6%D0%CE%C4 HTTP/1.1

现在IE下,\xXX这种看上像2位16进制值XX指定的1个字符(可能是Latin-1字符集的字符),如果想直接还原出“中文”2个字比较困难。
不过在与Firefox中的日志对比之下,能看出只要直接将\x替换成%,然后用PHP的urldecode反解析就能得到对应的字符串。

另外说明一点:
这个例子中看到的值%D6%D0%CE%C4,是按gbk字符集进行urlencode计算得到的对应值,如果urldecode反解析得到是乱码,则日志记录的应该是utf-8格式的urlencode值,用PHP的iconv函数处理一下。

Saturday, March 22, 2008

google gears on firefox2

Problem: the latest google gears version 0.3.11.0 can't install on firefox2.0.0.12.
Resolution: download google gears 0.3.2.0 version from neyric's blog , install it and restart firefox, google gears works.

Friday, March 21, 2008

difference of function toString() in IE7 and FF2

IE7:
alert(/x/.test(function(){'x';}))
// => true
(function(){'x';}).toString();
// => "(function(){'x';})"

FF2:
alert(/x/.test(function(){'x';}))
// => false
(function(){'x';}).toString();
// => "function () { }"

Tuesday, February 26, 2008

CSS float and document flow difference between firefox and ie7

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" >
<head>
<meta http-equiv="content-type" content="text/html; charset=GBK"/>
<title>css float and document flow difference between firefox and ie7</title>
<style type="text/css">
.paragraphs {border: 1px solid #ccc; width: 300px; float: left; margin: 10px;}
.divs {border: 3px double #333; width: 600px; margin: 2px;}
</style>
</head>
<body>
text content before float elements, blah, blah.......<br />
text content before float elements, blah, blah.......
<p class="paragraphs">
text content in paragraph which is left float.
text content in paragraph which is left float.
text content in paragraph which is left float.
text content in paragraph which is left float.
text content in paragraph which is left float.
text content in paragraph which is left float.
text content in paragraph which is left float.
</p>
text content after float elements, blah, blah.......
text content after float elements, blah, blah.......
text content after float elements, blah, blah.......
text content after float elements, blah, blah.......
text content after float elements, blah, blah.......
text content after float elements, blah, blah.......
<div class="divs">
text content in normal document flow, which container start point (left top) start after content ignore the float elements(double border div element), and which content will follow float elements. IE has some different tankle with this content, this container start point will after float element.
<br />
text content in normal document flow, which container start point (left top) start after content ignore the float elements(double border div element), and which content will follow float elements. IE has some different tankle with this content, this container start point will after float element.
</div>
</body>
</html>