js的showModalDialog对字符串的限制
来源:互联网 发布:webp转换jpg软件 编辑:程序博客网 时间:2024/06/02 04:29
不知道,大家有没有遇到这样的奇葩问题,当时今天笔者很不幸,遇到这一奇葩的问题,就当使用window.showModalDialog("test.jsp",args,'dialogHeight=100px;dialogWidth=250px;');进行数据传输,当args的数据大于4096个字符时,多出来的数据会被自动截掉,从而导致数据的完整性丢失.
Syntax
vReturnValue = window.showModalDialog(sURL [, vArguments] [, sFeatures])
Parameters
The vArguments parameter can be referenced within the modal dialog box using the dialogArguments property of the window object. If the vArguments parameter is defined as a string, the maximum string length that can be passed to the modal dialog box is 4096 characters; longer strings are truncated.
根据MSDN的说法,我们把args弄成object或array就行了,那么对于参数传出和传入的地方都需要修改"接口"的代码,这样一来未免就一些许麻烦。那么能不能让字符串参数突破args的4096个字符的限制呢?
其实对于一个字符串来说,只要我们把它包装成string object,就可以不再args长度的限制了,而且在Modal Dialog中处理字符串的接口函数不需要做任何的修改,如下代码:
function test(id){var _bpc;jQuery.ajax({url: 'test.html',data: {'id': id, 'name': name},type : "POST",async: false,cache : false,dataType : "json",success : function(data) {var result = json_parse(unescape(data));var selectHTML = [];if(result){if(result.length == 1){_bpc = {'id': result[0][0], 'name': result[0][1]};} else if(result.length > 1){selectHTML .push('<select name="">');for(var i = 0, le = result.length; i < le; i++){var item = result[i];selectHTML.push('<option id="bpc' + item[0] + '" value="' + item[0] + '">' + item[1] + '</option>');}selectHTML.push('</select>');alert(selectHTML.length);_obj = window.showModalDialog('index.html?'+'Math.random().toString()',selectHTML, 'dialogHeight=100px;dialogWidth=250px;');if(!_obj) _obj = {'id': -1, 'name': ''};}}},error: function(e){alert('查询失败,请稍后再试!');}});return _obj;}数据接收页面:
<script type="text/javascript" language="javascript">function finish(){var sel = document.getElementById('selDiv').firstChild;if(sel){var selectedItem = sel.options[sel.selectedIndex];window.returnValue = {'id': selectedItem.value, 'name': selectedItem.text};}window.close();}window.onload =function(){var args = window.dialogArguments;if(args != null){var bpcsArgs = args.join('');document.getElementById("selDiv").innerHTML = bpcsArgs;document.getElementById("selDiv").firstChild.focus();}}</script></head><body style="text-align: center;background: #ECE9D8; margin: 5px auto;" onkeydown="if(event.keyCode==13)finish()"><table align="center"><tr align="left"><td>该档案存在于以下流水类型中</td></tr><tr align="left"><td>请选择一个后点击确定</td></tr><tr align="center"><td><div id="selDiv"></div></td></tr><tr align="center"><td><input type="submit" value="确定" onclick="finish()" /> <input type="button" value="取消" onclick="window.close()" /></td></tr></table></body></html>
0 0
- js的showModalDialog对字符串的限制
- js对前台的限制
- js对输入用户名的限制
- JS中showModalDialog的用法
- js对字符串的处理
- JS对字符串的操作
- 模态窗口对字符串参数的巨无聊限制
- 模态窗口对字符串参数的巨无聊限制
- showModalDialog 4096限制,字符串参数突破方法
- 用js实现对text 输入框的限制
- JS 对输入框进行限制(常用的都有)
- JS 对输入框进行限制(常用的都有)
- 浅析js中的showModalDialog的实战应用
- 浅析js中的showModalDialog的实战应用
- js中showModalDialog和showModelessDialog的使用
- js中showModalDialog和showModalessDialog的区别
- js中showModalDialog和returnValue的用法
- js中showModalDialog的详细介绍
- 理解javascript异步机制(setTimeout )
- c语言课程设计 之 成绩管理系统
- C++标准库---排列元素next_permutation()&prev_permutation()
- Git学习笔记04--git checkout
- 多标记学习
- js的showModalDialog对字符串的限制
- Unity之编辑器类将摄像机视图(targetTexture)绘制在窗口中
- Oracle查看表中每个字段的统计信息脚本
- onload事件和js的defer设置
- CSplitterWnd 隐藏分割条 不崩溃
- CG_Hadoop:基于MapReduce的计算几何
- Leetcode-Majority Element
- tcp-ip Ping Program
- HDU 1003 Max Sum