js获取协议
1. 如何用JS来写应用层协议
7e ....... 7e 为一个包数据
4. 4. 2标识位
采用Ox7e表示,若校验码、消息头以及消息体中出现0x7e,则要进行转义处理,转义
规则定义如下:
0x7e<——>0x7d后紧跟一个0x02;
0x7d<——>0x7d后紧跟一个0x01。
4. 4. 4校验码
校验码指从消息头开始,同后一字节异或,直到校验码前一个字节,占用一个字节
标识位------- 消息体------- 校验码------- 标识位 整个包内容。
上面基本上可以保证包的数据是正确接受的。然后就看你内容要怎么搞。你可以把json字符串以utf-8转字节放进去。然后另一边以utf-8解析。然后2边都解析被解析后的字符串为json对象来交互。
我只是提供思路。因为协议很多,http、email、jt808,很多很多你可以自己看,或者看别人的文章是怎样设计协议。
更多问题可以去php中文网问答社区提问http://www.php.cn/wenda.html,大神在线帮你解决,希望对你有帮助
2. JS或PHP实现获取https协议下上一页URL
document.referrer,获取上一页的URL
再window.location
3. 如何快速获取返回协议头
如何快速抄获取返回协议头
Xcode,但你会发现它并不适合因为在代码格式化、自动完成和语法错误突出显示时它不是非常灵活。你可以通过学习本文来决定并选择合适的
JavaScript IDE。我用过 RudbyMine,但实际上任何 IDE 都支持 JavaScript。如果你能得到一个支持 JSX
的那真很不错。
当你打开 indx.ios.js 文件,你就会看到正在运行的应用程序构建 UI 的代码。你可能看到以下代码块。
'use strict'
4. js如何获取请求中的url以及参数
方法一、正则表达式
function getQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
var r = window.location.search.substr(1).match(reg);
if (r != null) return unescape(r[2]);
return null;
}
方法二、
<Script language="javascript">
function GetRequest() {
var url = location.search; //获取url中"?"符后的字串
var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);
strs = str.split("&");
for(var i = 0; i < strs.length; i ++) {
theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
}
}
return theRequest;
}
</script>
方法三、
/**
* 获取指定的URL参数值
* URL:http://www.quwan.com/index?name=tyler
* 参数:paramName URL参数
* 调用方法:getParam("name")
* 返回值:tyler
*/
function getParam(paramName) {
paramValue = "", isFound = !1;
if (this.location.search.indexOf("?") == 0 && this.location.search.indexOf("=") > 1) {
arrSource = unescape(this.location.search).substring(1, this.location.search.length).split("&"), i = 0;
while (i < arrSource.length && !isFound) arrSource[i].indexOf("=") > 0 && arrSource[i].split("=")[0].toLowerCase() == paramName.toLowerCase() && (paramValue = arrSource[i].split("=")[1], isFound = !0), i++
}
return paramValue == "" && (paramValue = null), paramValue
}
其他参数获取介绍:
//设置或获取对象指定的文件名或路径。
alert(window.location.pathname);
//设置或获取整个 URL 为字符串。
alert(window.location.href);
//设置或获取与 URL 关联的端口号码。
alert(window.location.port);
//设置或获取 URL 的协议部分。
alert(window.location.protocol);
//设置或获取 href 属性中在井号“#”后面的分段。
alert(window.location.hash);
//设置或获取 location 或 URL 的 hostname 和 port 号码。
alert(window.location.host);
//设置或获取 href 属性中跟在问号后面的部分。
alert(window.location.search);
5. javascript可以直接和pop3协议交互吗
javascript 自身没有对数据包处理能力,一般通过第三方方式 flash,asp,php,jsp,.net........
6. 取出js方法传入的参数的值
<Script language="javascript">
function GetRequest() {
var url = location.search; //获取url中"?"符后的字串
var theRequest = new Object();
if (url.indexOf("?") != -1) {
var str = url.substr(1);
strs = str.split("&");
for(var i = 0; i < strs.length; i ++) {
theRequest[strs[i].split("=")[0]]=(strs[i].split("=")[1]);
}
}
return theRequest;
}
</Script>
然后我们通过调用此函数获取对应参数值:
<Script language="javascript">
var Request = new Object();
Request = GetRequest();
var 参数1,参数2,参数3,参数N;
参数1 = Request[''参数1''];
参数2 = Request[''参数2''];
参数3 = Request[''参数3''];
参数N = Request[''参数N''];
</Script>
以此获取url串中所带的同名参数
二、正则分析法。
function GetQueryString(name) {
var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)","i");
var r = window.location.search.substr(1).match(reg);
if (r!=null) return (r[2]); return null;
}
alert(GetQueryString("参数名1"));
alert(GetQueryString("参数名2"));
alert(GetQueryString("参数名3"));
其他参数获取介绍:
//设置或获取对象指定的文件名或路径。
alert(window.location.pathname);
//设置或获取整个 URL 为字符串。
alert(window.location.href);
//设置或获取与 URL 关联的端口号码。
alert(window.location.port);
//设置或获取 URL 的协议部分。
alert(window.location.protocol);
//设置或获取 href 属性中在井号“#”后面的分段。
alert(window.location.hash);
//设置或获取 location 或 URL 的 hostname 和 port 号码。
alert(window.location.host);
//设置或获取 href 属性中跟在问号后面的部分。
alert(window.location.search);
7. 用js轻松判断当前网络协议是http还是https
JavaScript 的document对象中有一抄个location的子对象,其包括是属性如下:
document.location.host //表示当前域名 + 端口号
document.location.hostname //表示域名
document.location.href //表示完整的URL
document.location.port //表示端口号
document.location.protocol //表示当前的网络协议
所以通过上面第五条就能判断当前的网络协议了,具体判断如下:
[javascript] view plain
var protocolStr = document.location.protocol;
if(protocolStr == "http")
{
console.log("protocol = " + protocolStr);
}
else if(protocolStr == "https")
{
console.log("protocol = " + protocolStr);
}
else
{
console.log("other protocol");
}
8. 如何用JS得到当前页面的URL信息
设置或获取对象指来定的文源件名或路径。
<script>
alert(window.location.pathname)
</script>
设置或获取整个 URL 为字符串。
<script>
alert(window.location.href);
</script>
设置或获取与 URL 关联的端口号码。
<script>
alert(window.location.port)
</script>
设置或获取 URL 的协议部分。
<script>
alert(window.location.protocol)
</script>
设置或获取 href 属性中在井号“#”后面的分段。
<script>
alert(window.location.hash)
</script>
设置或获取 location 或 URL 的 hostname 和 port 号码。
<script>
alert(window.location.host)
</script>
设置或获取 href 属性中跟在问号后面的部分。
<script>
alert(window.location.search)
</script>
9. 一个js方法里调用两个自定义协议,但是只能调用到一个,求大神解答
首先,不明白这个定时器的作用是什么,其次可以尝试一下,点击666的时候,直接触发两个协议的点击事件可以吗?
10. js控制checkbox的选中,同意协议
提供两种方案参考:
1.在点提交按钮的时候验证checkbox是否选中
function confirmBox(){
var confirmBox = document.getElementById("cbId");//cbId为checkbox的ID
if(confirmBox.checked){
form.submit();
}else{
alert("请同意协议");
return false;
}
}
2. 隐藏提交按钮,选中checkbox后,才允许出现
初始化时disable掉提交按钮:<input id="submitBtn " type="button" disabled="disabled"/>
var confirmBox = document.getElementById("cbId");//cbId为checkbox的ID
var submitBtn = document.getElementById("submitBtn");//submitBtn为提交表单按钮的ID
function confirmBox(){
if(confirmBox.checked){
submitBtn.removeAttribute("disabled");
}else{
submitBtn.disabled="true";
}
}