IE8 中使用 javascript 打开新窗口时使用 GET 参数时出现的问题
我在使用 IE8 和使用 javascript 打开新窗口并提交带有特殊字符的参数时遇到问题。
<a href="javascript:oWin('/html/de/4664286/printregistrationcontent.html?12-security question=Wie heißt Ihr Lieblingsrestaurant','PRINT',800,600);" class="print">Seite drucken</a>
问题是字母“ß”(升号 S)。 正如您所看到的,上面的字符串是由于防 XSS 而进行编码的。 此链接适用于 FF 和 IE6,但 IE8 将 URL 参数作为代码 65*** 的字符传输(不知道 exaxt 值)。 在打开的窗口中您只会看到一个正方形(因为 65000+ 的字符不可打印)。
我还尝试使用 URL 编码而不是 HTML 编码
<a href="javascript:oWin('/html/de/4664286/printregistrationcontent.html?12-security question%3DWie hei%C3%9Ft Ihr Lieblingsrestaurant','PRINT',800,600);" class="print">Seite drucken</a>
如果我在 FF 或 IE6 中单击此链接,它会按预期工作,但 IE8 将无法将“ß”传输到服务器,因此也会以错误的方式返回它。 如果我将此 url 粘贴到 IE8,它也会起作用,但如果窗口是通过 javascript 打开的,则不起作用。
Javascript 函数 oWin 定义如下
function oWin(url,title,sizeH,sizeV) {
winHandle = top.open(url,title,'toolbar=no,directories=no,status=yes,scrollbars=yes,menubar=no,resizable=no,width='+sizeH+',height='+sizeV);
if(navigator.appVersion.indexOf("MSIE 3",0)==-1) id = setTimeout('winHandle.focus()',1000);
}
如果有人知道在哪里寻找原因,请回答这个问题。
谢谢 阿姆法
I have a problem with IE8 and the opening of a new window with javascript and submitting parameters with special characters.
<a href="javascript:oWin('/html/de/4664286/printregistrationcontent.html?12-security question=Wie heißt Ihr Lieblingsrestaurant','PRINT',800,600);" class="print">Seite drucken</a>
The Problem is the letter 'ß' (sharp S).
As you can see the string above is encodes due to anti XSS.
This link works in FF and IE6 but IE8 is transmitting the URL Parameter as character with code 65*** (don't know the exaxt value).
In the opening window you will only see a square (because character with 65000+ is not printable).
I also tried to use URL Encoding instead of HTML encoding
<a href="javascript:oWin('/html/de/4664286/printregistrationcontent.html?12-security question%3DWie hei%C3%9Ft Ihr Lieblingsrestaurant','PRINT',800,600);" class="print">Seite drucken</a>
If i click on this Link in FF or IE6 it works as expected, but IE8 will fail to transmit the "ß" to the server and therefor will also get it back in the wrong way.
If i paste this url to the IE8 it will work too, but not if the window is opened by javascript.
The Javascript function oWin is defined as follows
function oWin(url,title,sizeH,sizeV) {
winHandle = top.open(url,title,'toolbar=no,directories=no,status=yes,scrollbars=yes,menubar=no,resizable=no,width='+sizeH+',height='+sizeV);
if(navigator.appVersion.indexOf("MSIE 3",0)==-1) id = setTimeout('winHandle.focus()',1000);
}
If someone has an idea where to look for the reason please answer to this.
Thank you
amfa
并非所有浏览器都以相同的方式对 href 属性进行编码 - 这可能是您的问题。
我想您会发现,如果将代码移至
onclick
属性,它将以不同的方式进行处理,并且跨浏览器的处理更加一致。然而,以这种方式添加 onclick 事件不一定是好的设计 - 最好在 javascript 中添加处理程序,而不是在属性标记本身中,但至少值得尝试。
...确保在 onclick 处理程序中返回 false 以防止 href 链接被跟踪。
Not all browsers encode the href attribute the same way - this could be your problem.
I think you will find that if you move the code to the
onclick
attribute, it will be handled differently, and more consistently across browsers.Adding onclick events in this manner however is not necessarily good design - its best to add handlers in javascript rather than in the attribute tag itself, but it might be worth at least trying.
...make sure you return false in the onclick handler to prevent the href link being followed.