當用戶的頁面需要動態加載iframe 時,
如果iframe的src中包傳中文參數會出現編碼錯誤;必須加編碼,然後再解碼。
編碼:encodeURI(encodeURI("包含中文的串"))
解碼:java.net.URLDecoder.decode("需要解碼的串","utf-8");
解決方案
使用encodeURI('中文') 進行編碼操作,
js代碼:
複製代碼代碼如下:
$(function() {
$('#frame').attr('src', '${basePath}mi/right.do?bidItemName=' +encodeURI('中文'));
});
html代碼
複製代碼代碼如下:
<html>
<body>
<iframe src="" scrolling="no" frameBorder=0 id="frame"></iframe>
</body>
</html>