Skip to content

send state pass array is not array form one page to another page  #114

@wzhonggo

Description

@wzhonggo

Content-Type is application/json if state value is Array. But Content-Type is application/octet-stream if you pass Array form one page to another page . The reason is use instanceof to test state value .

see javascript-when-i-pass-array-from-iframe-function-the-array-lose-his-type

Test in chrome with windows 10.
t1. html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        function test() {
            var arr = [];
            arr.push(1);
            var r1 = arr instanceof Array;
            console.log("is array (instanceof) " + r1.toString());
            console.log("is array (Array.isArray) " + Array.isArray(arr))
            console.log("call iframe")
            window.f1.demo(arr);
        }
    </script>
</head>
<body>
<iframe src="t2.html" name="f1"  height="600" width="100%" frameborder="0" scrolling="no" onload="test()"></iframe>
</body>
</html>

t2.html

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Title</title>
    <script>
        demo = function (param) {
            var r1 = param instanceof Array;
            console.log("is array (instanceof) " +  r1.toString())
            console.log("is array (Array.isArray) " +  Array.isArray(param))
        }
    </script>
</head>
<body>
</body>
</html>

The consloe result

is array (instanceof) true
is array (Array.isArray) true
call iframe
is array (instanceof) false
is array (Array.isArray) true

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions