【发布时间】:2016-03-20 17:36:17
【问题描述】:
我正在使用 javascript 函数将一些表单数据(使用 get)发送到弹出窗口。 两个页面都有 utf-8 编码。但弹出显示特殊值错误(如 �)。此问题仅在 Internet Explorer 上发生。当我将编码更改为 windows-1254 时,它返回正常。页面编码应该保持不变。 使用 mb_detect_encoding() 检查 $_GET 数据;它给出了 UTF-8 结果。 知道是什么原因造成的吗?
function NewCustomer(field1,field2,field3){
OpenPopup('Customer/New.php?field1='+ field1 +'&field2='+ field2 +'&field3='+ field3 +'', 'NewCustomer', 'channelmode=0, directories=0, fullscreen=0, width=550, height=460, location=0, menubar=0, resizable=0, scrollbars=1, status=0, titlebar=1, toolbar=0', false);
}
echo $_GET['fieldname'];
function OpenPopup( url, winname, features )
{
if(winname==''){
window.open( url, winname, features, false );
return;
}
if ( !findWindow( url, winname, features ) )
{
var handle = window.open( url, winname, features, false );
if ( handle != null ) handle.focus();
}
}
function findWindow( url, winname, features )
{
var handle = window.open( '', winname, features, false );
if ( handle != null )
{
if (( handle.location != 'about:blank' ) && ( handle.location != '' ))
{
handle.focus();
return true;
}
}
return false;
}
编辑
我用 iconv 修复了 IE 问题。但现在,问题开始出现在其他浏览器上。
iconv('windows-1254', 'UTF-8', $_GET['field']);
最后编辑
这是最终解决方案。
<?php if(isset($_GET['fieldname'])) {
preg_match('/MSIE (.*?);/', $_SERVER['HTTP_USER_AGENT'], $matches);
if (count($matches)>1){ echo iconv('windows-1254', 'UTF-8', $_GET['fieldname']); } else { echo $_GET['fieldname']; }
} ?>
【问题讨论】:
-
没有代码,我们都在猜测。
-
OpenPopup是标准的 PHP 函数吗?我找不到它的文档。 -
@JoachimIsaksson 不是。我添加了功能代码。