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";
}
}