javascript - window.location.href 不重定向
问题描述
我的功能如下
<a onClick="check_claims(this)" type="button" href="javascript:void(0)" redirurl="www.facebook.com" >Invite</a>
function check_claims(ele){
var select_claims = document.getElementById('select_claims').value;
if (select_claims == '1') {
var result = confirm("do you wish to continue?");
if (!result) {
check_email_address();
return;
}
}
check_email_address();
window.location.href = ele.getAttribute('redirurl');
}
function check_email_address(){
if ('{{broker.email_address}}' == 'None') {
console.log('this worked till here');
window.location.href = 'www.google.com';
}
}
我刚刚添加了第二个功能check_email_address
。该函数被调用并打印日志,但windows.location.href
该函数的 没有得到评估,页面不断重定向到window.location.href
第一个函数中提到的 url。
解决方案
尝试return false;
在处理程序的末尾使用。
您可以参考这个问题了解更多详情。
编辑:请试试这个。
function check_claims(ele){
var select_claims = document.getElementById('select_claims').value;
if (select_claims == '1') {
var result = confirm("do you wish to continue?");
if (!result) {
check_email_address();
return;
}
}
var email_check = check_email_address();
if (!email_check) window.location.href = ele.getAttribute('redirurl');
}
function check_email_address(){
if ('{{broker.email_address}}' == 'None') {
console.log('this worked till here');
window.location.href = 'www.google.com';
return true;
}
return false;
}
推荐阅读
- regex - 如何按照自定义模式从变量获取所有字符串实例到bash中的数组?
- r - 获取 c++ 异常尝试使用 rvest 和 V8 抓取 javascript 呈现的网页
- css - 我如何内联显示 React 组件
- python - 使用 Beautiful Soup 在嵌套标签中查找价值
- visual-studio - 如何解决 nuget 包错误?
- php - 在 PHP 中循环并存储关联数组中的键值
- sas - 如何使用 palote 字符作为分隔符在 sas 中创建 .txt 文件?
- vue.js - 如何使用 VueBlobJsonCsv 从 API 提取数据并转换为 CSV
- c# - 如何正确地将 C# 中的双精度数组发送到 C dll?
- python - 我如何按seaborn的升序/降序对直方图条进行排序?