www.test.com
<?php @ini_set(‘default_charset‘, ‘utf-8‘); ?> <input type="text" value="send" id="input" /> <input type="button" value="send" id="button" /> <script type="text/javascript" src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script> <script> document.getElementById(‘button‘).onclick = function () { var command = "$(window.document.body).append(‘数据‘)"; window.parent.postMessage(‘run:‘ + command, document.referrer); }; </script>
另外域名的 www.test2.com
<?php @ini_set(‘default_charset‘, ‘utf-8‘); ?> <iframe src="http://www.test.com/test2.php"></iframe> <script type="text/javascript" src="http://libs.baidu.com/jquery/1.10.2/jquery.min.js"></script> <script> var rootUrl = ‘http://www.test.com/‘; $(window).on(‘message‘, function (e) { var command = e.originalEvent.data, origin = e.originalEvent.origin; if ((rootUrl == origin || rootUrl == origin + ‘/‘) && typeof command == ‘string‘ && command.substr(0, 4) == ‘run:‘) { command = command.substr(4); eval(command); } }); </script>
时间: 2024-10-15 06:10:24