[英]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
對象,並且調用stopPropagation
和preventDefault
將引發異常,因為沒有此類方法 。
如果在表單提交內調用checkcat
,請記住包括return
以阻止表單提交:
<form onsubmit="return checkcat()">
</form>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.