W3Cschool
恭喜您成為首批注冊用戶
獲得88經(jīng)驗(yàn)值獎(jiǎng)勵(lì)
1.3.1【必須】限定跳轉(zhuǎn)目標(biāo)地址
location.href
、window.open()
、location.assign()
、location.replace()
;賦值或更新HTML屬性:a.href
、ifame.src
、form.action
、embed.src
、object.data
、link.href
、area.href
、input.formaction
、button.formaction
;// bad: 跳轉(zhuǎn)至外部可控的不可信地址
const sTargetUrl = getURLParam("target");
location.replace(sTargetUrl);
// good: 白名單限定重定向地址
function validURL(sUrl) {
return !!((/^(https?:\/\/)?[\w\-.]+\.(qq|tencent)\.com($|\/|\\)/i).test(sUrl) || (/^[\w][\w/.\-_%]+$/i).test(sUrl) || (/^[/\\][^/\\]/i).test(sUrl));
}
const sTargetUrl = getURLParam("target");
if (validURL(sTargetUrl)) {
location.replace(sTargetUrl);
}
// good: 制定重定向地址為固定值
const sTargetUrl = "http://www.qq.com";
location.replace(sTargetUrl);
Copyright©2021 w3cschool編程獅|閩ICP備15016281號(hào)-3|閩公網(wǎng)安備35020302033924號(hào)
違法和不良信息舉報(bào)電話:173-0602-2364|舉報(bào)郵箱:jubao@eeedong.com
掃描二維碼
下載編程獅App
編程獅公眾號(hào)
聯(lián)系方式:
更多建議: