区分是否为外部URL时加入了正则校验

This commit is contained in:
李皓宸
2019-05-29 11:05:28 +08:00
parent 8770f98ea1
commit c0461322fa

View File

@@ -152,7 +152,7 @@ function page_turn(id, functionId,level, name, url,obj){
//调入页面
//进行区分是否为外部URL
if (url.split("http").length>1) {
if (postComment(url)) {
url="http"+url.split("http")[url.split("http").length-1]+"?test_cookie="+lang;
}else{
if(url.indexOf("?")>0){
@@ -162,6 +162,7 @@ function page_turn(id, functionId,level, name, url,obj){
}
}
window.frames['mainFrame'].location=url;
$("#mainFrame").load(function(){
@@ -169,6 +170,25 @@ function page_turn(id, functionId,level, name, url,obj){
});
}
/**
* 前台页面验证url网址输入是否正确
*/
function postComment(str) {
//验证url网址
//判断URL地址的正则表达式为:http(s)?://([\w-]+\.)+[\w-]+(/[\w- ./?%&=]*)?
//下面的代码中应用了转义字符"\"输出一个字符"/"
var Expression=/http(s)?:\/\/([\w-]+\.)+[\w-]+(\/[\w- .\/?%&=]*)?/;
var objExp=new RegExp(Expression);
if(objExp.test(str) != true){
return false;
} else {
return true;
}
}
function searchMenu() {