I'm rather new to jQuery but managed to get some social links to open in a new controlled window instead of new tab. I have a few functions that do the same thing, and this works, but there is always a better method.
I did review the question and answer here and couldn't figure out which would apply to this case.
jQuery(document).ready(function ($) {
$("#ssba_facebook_share").attr('title','opens in a new pop-up');
$("#ssba_facebook_share").click(function(){
w = parseInt((screen.width - 600)/2); h = parseInt((screen.height - 400)/2);
cwin = window.open($(this).attr('href'), 'closewin',
'status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0,height=400,width=600');
cwin.moveTo(w,h);
return false;
});
$("#ssba_twitter_share").attr('title','opens in a new pop-up');
$("#ssba_twitter_share").click(function(){
w = parseInt((screen.width - 600)/2); h = parseInt((screen.height - 400)/2);
cwin = window.open($(this).attr('href'), 'closewin',
'status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0,height=400,width=600');
cwin.moveTo(w,h);
return false;
});
$("#ssba_google_share").attr('title','opens in a new pop-up');
$("#ssba_google_share").click(function(){
w = parseInt((screen.width - 600)/2); h = parseInt((screen.height - 400)/2);
cwin = window.open($(this).attr('href'), 'closewin',
'status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0,height=400,width=600');
cwin.moveTo(w,h);
return false;
});
});
Now, I've attempted a few things to no avail, and one method was this:
jQuery(document).ready(function ($) {
$("#ssba_facebook_share","#ssba_twitter_share","#ssba_google_share").attr('title','opens in a new pop-up');
$(this).click(function(){
w = parseInt((screen.width - 600)/2); h = parseInt((screen.height - 400)/2);
cwin = window.open($(this).attr('href'), 'closewin',
'status=0,toolbar=0,location=0,menubar=0,directories=0,resizable=0,scrollbars=0,height=400,width=600');
cwin.moveTo(w,h);
return false;
});
});
Does anyone have any pointers in this, if possible, with a description of where I went wrong? Or even post a link to a question that goes over this in laymen terms? (I've been looking around and found similar posts, which is how I arrived at where I am now, but still having trouble making complete sense of it.)