Click here to Skip to main content
15,893,814 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
This is my code:

JavaScript
var opened='';
var opened1='';	
var i=0;
var j=0;

$( "#dialog-confirm" ).dialog({

  	resizable: true,
  	modal: true,
    buttons: {

        "Yes": function() {

           	$( this ).dialog( "close" );
           	$.ajax({
	           	url: urlDetail,
	           	type: 'POST',
	           	data: {page_title: proTitle, page_url: proUrl, product_description: proDescription, product_image: proImage, web: proHost, product_price: proPrice, purchased: 'yes' },
           	})
           	.done(function() {
           		console.log("success");
	           	if(j==0){
    		       	opened1=window.open(urlDetail,"Spost1","status=1,width=870,height=530");
    		       	j=1;
    		    }else{
    		    	opened1=window.open(urlDetail,"Spost1","status=1,width=870,height=530");
    		    	opened1.focus(); 
          		    } 
           	})
           	.fail(function() {
           		console.log("error");
           	})
           	.always(function() {
           		console.log("complete");
           	}); 
        },
        "No": function() {

          	$( this ).dialog( "close" );

          	$.ajax({
	           	url: urlDetail,
	           	type: 'POST',
	           	data: {page_title: proTitle, page_url: proUrl, product_description: proDescription, product_image: proImage, web: proHost, product_price: proPrice, purchased: 'no' },
           	})
           	.done(function() {
           		console.log("success");
	           	if(i==0){
	           		console.log("first-time: "+i);
    		       	opened=window.open(urlDetail,"Spost","status=1,width=870,height=530");
    		       	i=1;
    		    }else{
    		 		console.log("2nd-time: "+i);
    		    	opened=window.open(urlDetail,"Spost","status=1,width=870,height=530");
    		    	opened.focus();
          		    } 
           	})
           	.fail(function() {
           		console.log("error");
           	})
           	.always(function() {
           		console.log("complete");
           	}); 	 
	        
        }
    }

});


So, here focus to already opened window is not working
Posted
Updated 19-Aug-15 19:44pm
v3
Comments
Did you debug?
Member 11920335 20-Aug-15 1:46am    
yes its only refresh window not bring focus to window when window is already opened.
Member 11920335 20-Aug-15 2:08am    
both solutions are not working in my case

1 solution

$( "#dialog-confirm" ).dialog({

	resizable: true,
        modal: true,
	buttons: {

	"Yes": function() {

	opened = window.open(urlDetail,"Spost","status=1,width=870,height=530");
        opened.focus();

	$( this ).dialog( "close" );

        $.ajax({
	    url: urlDetail,
	    type: 'POST', 
	    data: {page_title: proTitle, page_url: proUrl, product_description:     proDescription, product_image: proImage, web: proHost, product_price: proPrice, purchased: 'yes' },
	})
	.done(function() {
	  console.log("success");				           		      
							      
	  opened=window.open(urlDetail,"ShoppingPost","status=1,width=870,height=530");
          opened.focus(); 
			      	          		   
	})
	.fail(function() {
	   console.log("error");
	})
	.always(function() {
	  console.log("complete");
	}); 
      },
      "No": function() {						       
         opened = window.open(urlDetail,"Spost","status=1,width=870,height=530");
         opened.focus();

	 $( this ).dialog( "close" );

	 $.ajax({
	   url: urlDetail,
	   type: 'POST',
	   data: {page_title: proTitle, page_url: proUrl, product_description: proDescription, product_image: proImage, web: proHost, product_price: proPrice, purchased: 'no' },
	})
	.done(function() {					             
	   console.log("success");				           	
           opened = window.open(urlDetail,"ShoppingPost","status=1,width=870,height=530");
	   opened.focus();    
			      	          		     
	})
	.fail(function() {
	    console.log("error");
        })
	.always(function() {
            console.log("complete");
	}); 	 
							        
      }
    }

});
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900