Restrictions on strings in js showModalDialog

Source: Internet
Author: User

Restrictions on strings in js showModalDialog

I don't know, have you ever encountered such a strange problem? At that time, I was very unfortunate today. When I encountered such a strange problem, I should use window.ShowModalDialog("Test. jsp ", args, 'dialogheight = 100px; dialogWidth = 250px; '); for data transmission, when The args data exceeds 4096 characters, the extra data will be automatically truncated, this results in data integrity loss.

Syntax
VReturnValue = window. showModalDialog (sURL [, vArguments] [, sFeatures])
Parameters

SURL Required.StringThat specifies the URL of the document to load and display.
VArguments Optional. variant that specifies the arguments to use when displaying the document. use this parameter to pass a value of any type, including an array of values. the dialog box can extract the values passed by the caller fromDialogArgumentsProperty ofWindowObject.
MSDN provides the following identifiers:
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.

According to MSDN, we can make args an object or an array. Therefore, the code of the "interface" must be modified for the outgoing and incoming parameters, in this way, it is a little troublesome. Can the string parameter be broken through the 4096 characters limit of args?

In fact, for a string, as long as we wrap it into a string object, we can no longer limit the length of args, and the interface function for processing strings in Modal Dialog does not need to be modified, the following code:

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 (''); For (var I = 0, le = result. length; I <le; I ++) {var item = result [I]; selectHTML. push (''+ Item [1] +'');} SelectHTML. push (''); Alert (selectHTML. length); _ obj = require repeated showmodaldialog('index.html? '+ 'Math. random (). toString ()', selectHTML, 'dialogheight = 100px; dialogWidth = 250px; '); if (! _ Obj) _ obj = {'id':-1, 'name': ''}}}, error: function (e) {alert ('query failed, please try again later! ') ;}}); Return _ obj ;}
Data receiving page:

<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>
 
 
This file exists in the following flow type
Select one and click OK.




Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.