Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
wzhonggo opened this issue Sep 22, 2018 · 0 comments
Open

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

wzhonggo opened this issue Sep 22, 2018 · 0 comments

Comments

@wzhonggo
Copy link

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

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant