簡體   English   中英

window.open不適用於_self

[英]window.open not working for _self

請看一下我下面的js函數。 如果我在沒有_self屬性的情況下進行重定向,則該功能可以正常工作。 同樣,無論我沒有停止重定向頁面本身的原因是什么,我都認為這就是_self不起作用並對_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;
}

return false完成工作。 在您的方法中,您不會傳遞event對象,並且調用stopPropagationpreventDefault 將引發異常,因為沒有此類方法

如果在表單提交內調用checkcat ,請記住包括return以阻止表單提交:

<form onsubmit="return checkcat()">
</form>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM