$ (". Ajax"). On ("click",function() { //var newtab=window.open (' About:blank '); varIndex = $ ( This). Data ("index"); $.post ("/ajax/operation/openredenvelopetask", {taskid:index},function(data) {if(Data.errno = = 0){ if(index===1){ //Jump Task 1 //window.open (' http://cp01-baike-epc017.epc.baidu.com:8900/task/201131 '); //newtab.location.href= "http://cp01-baike-epc017.epc.baidu.com:8900/task/201131"; //window.location.href = '/task/201131 '$ (' #t_form ' +index). Submit (); }Else if(index===2){ //Jump Task 2 //window.open (' http://cp01-baike-epc017.epc.baidu.com:8900/task/201508 '); //newtab.location.href= "http://cp01-baike-epc017.epc.baidu.com:8900/task/201508"; //window.location.href= "http://cp01-baike-epc017.epc.baidu.com:8900/task/201508";$ (' #t_form ' +index). Submit (); $('. Btn ' +index). Removeclass (' Btn-edit '). addclass (' btn-go '). Text (' Keep doing ')); } } Else if(Data.errno = = 1) { $('. Btn ' +index). Removeclass (' Btn-edit '). Removeclass (' btn-go '). "Text (' Up to today's limit ')); //newtab.close (); //return false;}Else if(Data.errno = = 2) {userlogin.showloginpop (); //return false; } }, "JSON"); });
1. Directly in JS call window.open () function to open a new window, the browser will intercept you, by the following method to avoid
is to first open a window with window.open and then modify the address. such as Var tempwindow=window.open (' _blank '); open a window and then use tempwindow.location= ' http://www.baidu.com '; make this window jump to Baidu, This will show the effect of the pop-up Baidu window.
$ ("#last"). Click (function() {var w=window.open (); SetTimeout (function () {w.location= "http://www.baidu.com"); return false /////
But when the need to close a flash phenomenon,
2. window.location.href = ' xxxx ', but will not open a new window
3.form submit (); To achieve
<!DOCTYPE HTML><HTMLLang= "en"> <Head> <MetaCharSet= "UTF-8"> <title>Document</title> <styletype= "Text/css"> *{margin:0;padding:0;}#j_form{position:Absolute; Left:-999em;} </style> </Head> <Body> <formID= "J_form"Action= "Http://www.baidu.com"Target= "_blank"Method= "POST"></form> <ButtonID= "J_btn">Click Me</Button> <Scriptsrc= "Http://apps.bdimg.com/libs/jquery/2.1.4/jquery.min.js"type= "Text/javascript"></Script> <Scripttype= "Text/javascript"> $('#j_btn'). On ('Click',function(){ $('#j_form'). Submit (); }); </Script> </Body></HTML>
The 4.jquery trigger () method simulates triggering, but the href in a tag cannot be controlled by JS, but can use trigger () bubbling feature, <a href= "http://baike.baidu.com/task/200414 "target=" _blank "class=" btn "><span class=" JUMP1 "></span></a>
$ (' #jump1 '). Trigger (' click ');
Click a button to determine the jump and other states based on the results returned by Ajax