本帖最后由 宇智波·佐助 于 2021-10-26 11:16 编辑
36-奇易浏览框填表之WebSockett通信,执行JS命令
下载:https://share.weiyun.com/v8YQxlcH
//https://blog.csdn.net/wangzhanzheng/article/details/78603532 WebSocket 调用方法 //1、parent常用在iframe和frame中的子页面访问父页面中的对象 2、top :一个页面可能会有很多层,top是指最顶层的框架 3、self :是指当前窗口 if (top.location!=self.location){var fd_timer = setInterval ("fd_wati ()", 500);}else{fd_conn ();} //开启网络通信 var fd_ws;//创建WebSocket通信协议变量 var fd_str = ""; var fiddler_form = "标识符"; var fd_del = false; var autoint; var xtint; function fd_xintiao (){fd_ws.send ("xtb->");}//发送心跳包 function fd_conn () { var size = 5000; var xd1 = 0; var bzf = ""; console.log ("【填表】正在尝试填表连接"); fd_ws = new WebSocket ("ws://127.0.0.1:6002/echo"); //建立在 TCP 协议 客户端 fd_ws.onopen = function (){ console.log ("【填表】连接到填表服务器成功:"+autoint);fd_ws.send ("csh->"+fiddler_form);clearInterval (autoint);autoint=0;xtint=setInterval ("fd_xintiao ()", 10000);};//用于指定连接成功后的回调函数 fd_ws.onclose = function (){if (autoint<=0){console.log ("【填表】断开连接,正常重试");autoint = setInterval ("fd_conn ()", 5000);clearInterval (xtint);}}; //用于指定连接关闭后的回调函数 //fd_ws.onmessage用于指定收到服务器数据后的回调函数 fd_ws.onmessage = function (evt){ if (fd_del == true){fd_str = ""; fd_del= false;} fd_str = fd_str + evt.data; console.log (evt.data) if (fd_str.substr (fd_str.length-2,2) == " ##" ;){ fd_del = true; fd_str = fd_str.substr (0,fd_str.length-2); var text = eval (decodeURI (fd_str)); fd_ws.send ("dat->"+text+"<-dat"); }; return null;}; } function fd_wati () { var fd = str_mid (window.location.href," #fd ="," #" ;); if (fd!=null){ fiddler_form = fd; clearInterval (fd_timer);//停止循环执行setInterval ()函数 fd_conn (); } } function str_mid (str,a,b){ strlen = str.length; var wz1 = str.indexOf (a); if (wz1<=-1){return ;} var wz2 = str.indexOf (b,wz1+a.length); if (wz2==-1){return ;} console.log (str.substr (wz1+a.length,wz2-wz1-a.length)); return str.substr (wz1+a.length,wz2-wz1-a.length); }
|