-
Notifications
You must be signed in to change notification settings - Fork 118
Open
Description
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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels