js实现url链接encode加密
function urlencode(clearString) {
var output = '';
var x = 0;
clearString = utf16to8(clearString.toString());
var regex = /(^[a-zA-Z0-9-_.]*)/;
while (x < clearString.length) {
var match = regex.exec(clearString.substr(x));
if (match != null && match.length > 1 && match[1] != '') {
output += match[1];
x += match[1].length;
} else {
if (clearString[x] == ' ') {
output += '+';
} else {
var charCode = clearString.charCodeAt(x);
var hexVal = charCode.toString(16);
output += '%' + ( hexVal.length < 2 ? '0' : '' ) + hexVal.toUpperCase();
}
x++;
}
}
return output;
}
function utf16to8(str) {
var out, i, len, c;
out = "";
len = str.length;
for(i = 0; i < len; i++) {
c = str.charCodeAt(i);
if ((c >= 0x0001) && (c <= 0x007F)) {
out += str.charAt(i);
} else if (c > 0x07FF) {
out += String.fromCharCode(0xE0 | ((c >> 12) & 0x0F));
out += String.fromCharCode(0x80 | ((c >> 6) & 0x3F));
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
} else {
out += String.fromCharCode(0xC0 | ((c >> 6) & 0x1F));
out += String.fromCharCode(0x80 | ((c >> 0) & 0x3F));
}
}
return out;
}
js实现url链接encode加密的更多相关文章
- js 获取url链接的任意参数
<script> //先获取 当前的url链接 var url = location.href; //把url 链接切割为数组 var arr = url.split("&quo ...
- js复制URL链接
html: <div style="height:0px; text-indent:-10000px;"><span id="hdcopyurl&quo ...
- js获取url链接中的域名部分
用js提取出url中的域名(domain)部分,用split()函数就可以了. 因为一个正确的url必定是由http://或者是https://.domain.路径/参数组成,所以可以用split以/ ...
- 通过JS获取URL链接带的参数
1 /** 2 * 获取URL参数的方法 3 */ 4 $.extend({ //以便于通过$引用该方法 5 getUrlVars : function() { //获取多个参数数组 6 var va ...
- js获取url链接地址的参数
访问地址为:http://XXX.com?style=green <script language="javascript"> var getArgs = functi ...
- JS URL 使用base64加密与解密
JS编码方式: <script type="text/javascript"> document.write(encodeURI("http://www.w3 ...
- JS URL 使用base64加密与解密和MD5解密
JS编码方式: <script type="text/javascript"> document.write(encodeURI("http://www.w3 ...
- URL链接中文参数乱码的若干处理方法
JAVA 中URL链接中文参数乱码的若干处理方法,现在整理收录如下: 方法一: (1) JS中,在URL参数中确保用UTF-8编码,用js函数encodeURI()编码,例如 url:"xx ...
- Js中 md5 sha1 base64 加密
js的3中加密方式: .sha1加密,加密性高 调用: var sha = hex_sha1(str); .base64加密 调用: var b = new Base64(); var str = b ...
随机推荐
- 训练[2]-DFS
题目A: 题目B[https://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_pro ...
- 转:条件变量、pthread_cond_init
1.初始化条件变量pthread_cond_init #include <pthread.h>int pthread_cond_init(pthread_cond_t *cv,const ...
- Gdiplus 贴图(助记) -------------------从资源中载入PNG图片
从资源中载入图片,亦可改为从内从中加载: void LoadResImage(int nResID,Image * &lpImage) { HINSTANCE hIns=AfxGetInsta ...
- UIView 和 CALayer 的区别和联系
UIView是在/System/Library/Frameworks/UIKit.framework定义,也就是处于Cocoa Touch层. CALyer是在/System/Library/Fram ...
- 新项目引入gulp
1:安装npm:官网下载nodejs--https://nodejs.org/en/.进行安装npm;--http://jingyan.baidu.com/article/a17d528506d7f5 ...
- form里面的action和method(post和get的方法)使用
一.form里面的action和method的post使用方法 <%@ Page Language="C#" AutoEventWireup="true" ...
- redis :初步使用
redis : 1.ubuntu安装 'pip install redis-server' 2.启动 'redis-cli' 3.使用 set: set a 1 get: get a fl ...
- C# 读书笔记之类与结构体
类和结构体都包括数据和操作数据的方法 类的定义形式 class PhoneCustomer{public const string DayOfSendingBill = "Monday&qu ...
- 图的存储结构:邻接矩阵(邻接表)&链式前向星
[概念]疏松图&稠密图: 疏松图指,点连接的边不多的图,反之(点连接的边多)则为稠密图. Tips:邻接矩阵与邻接表相比,疏松图多用邻接表,稠密图多用邻接矩阵. 邻接矩阵: 开一个二维数组gr ...
- linux 移除svn文件夹
find . -name .svn -type d -exec rm -fr {} \;