Javascript window.open不为自己工作
请看一下我下面的js函数。如果我在没有_self属性的情况下执行重定向,该函数可以正常工作。另外,无论我做了什么,它都没有停止页面本身的重定向,我认为这就是为什么Javascript window.open不为自己工作,javascript,jquery,Javascript,Jquery,请看一下我下面的js函数。如果我在没有_self属性的情况下执行重定向,该函数可以正常工作。另外,无论我做了什么,它都没有停止页面本身的重定向,我认为这就是为什么\u self不工作,并且对于\u blank工作良好的原因 function checkcat() { if ($(".caty").find(".active-cat").length > 0){ window.open("http://www.google.com","_self"); // windo
\u self
不工作,并且对于\u blank
工作良好的原因
function checkcat()
{
if ($(".caty").find(".active-cat").length > 0){
window.open("http://www.google.com","_self");
// window.open("http://www.google.com","_blank");
}
else
{
alert('Aloha!!!');
// Following I used to strictly stop the redirection but it didnot work :(
stopPropagation();
preventDefault();
return false;
}
}
要防止页面提交,您需要执行以下操作:
function checkcat() {
if ($(".caty").find(".active-cat").length > 0){
window.open("http://www.google.com","_self");
}
else {
alert('Aloha!!!');
}
return false;
}
只有返回false
才能执行此操作。在您的方法中,您不传入事件
对象,调用stopPropagation
和preventDefault
将引发异常,因为没有此类方法
如果在表单提交中调用checkcat
,请记住包含return
以停止表单提交:
<form onsubmit="return checkcat()">
</form>