js将网址转为urlencode类型
来源:互联网 发布:iphone写作软件 编辑:程序博客网 时间:2024/05/01 07:38
当做passport项目时需要做跳转URL,一般的方式都是使用php自带的urlencode方式解决,现在好JS也能处理了!
调用方法,将下面函数写在一个js文件,支持调用
将要encode 的网址改
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>无标题文档</title><script> function UrlEncode(str) { return transform(str); } function transform(s) { var hex='' var i,j,t j=0 for (i=0; i<s.length; i++) { t = hexfromdec( s.charCodeAt(i) ); if (t=='25') { t=''; } hex += '%' + t; } return hex; } function hexfromdec(num) { if (num > 65535) { return ("err!") } first = Math.round(num/4096 - .5); temp1 = num - first * 4096; second = Math.round(temp1/256 -.5); temp2 = temp1 - second * 256; third = Math.round(temp2/16 - .5); fourth = temp2 - third * 16; return (""+getletter(third)+getletter(fourth)); } function getletter(num) { if (num < 10) { return num; } else { if (num == 10) { return "A" } if (num == 11) { return "B" } if (num == 12) { return "C" } if (num == 13) { return "D" } if (num == 14) { return "E" } if (num == 15) { return "F" } } } function goto(){location.href='http://demo3.test.com/tt.php?url='+UrlEncode('http://www.baidu.com/baidu?wd=%C0%CB%C2%FE%C2%FA%CE%DD&tn=monline_4_dg');}//alert(UrlEncode("http://www.baidu.com/")); </script></head><body><a href="#" onclick="goto()">1212</a></body></html>
- js将网址转为urlencode类型
- 将string转为HtmlElement类型
- 将Entity转为Map类型
- js将object转为字符串
- js string转为date类型
- 如何将IntPtr类型转为Image类型
- 将String类型转为int类型
- 将任意类型转为number类型
- js urlencode
- js 将json字符串转为js对象
- 将json数据(JSONObject类型)进行URLEncode编码
- ios 将时间戳转为时间类型
- QT 下将Qstring转为char *类型
- 如何将TParams类型转为Variant?
- 如何将TParams类型转为Variant?[转]
- delphi如何将real类型转为pchar
- JavaScript将String转为double类型
- Sql 将字符串转为double类型
- 对话框结构体
- 编译boost在ios上使用
- android Notification 的使用
- Vi替换
- 残盘覆盖
- js将网址转为urlencode类型
- AppWidget如何打开一个Acticity?
- python random模块
- 旅游
- 面试100题:21.中兴面试题:求整数数列中和等于给定值的两个数
- 递归读取文件目录结构
- Bruno Buchberger: A life devoted to symbolic computation
- Oracle Data Guard支持跨平台列表
- Access MAC address from sk_buff