I'm developing a database-sharing URL saving system every time I click on one of the site's social networks.
It turns out that the window.open
that I use to access the social network is not working after the Ajax call.
Does anyone have any idea why this happens?
An example of the sharing link:
teste.com.br/teste?c=xyoz&cc=1
cc=1
is lastInsertId();
when you save the share.
HTML:
<a href="https://www.facebook.com/sharer/sharer.php?u=<?php echo rawurlencode($url."&c=cd3a0725fa81899"); ?>" class="popup" title="Compartilhe com Facebook" rede-social="facebook">
<span class="icon">
<svg version="1.1" id="Layer_1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" x="0px" y="0px" width="18px" height="18px" viewBox="0 0 28 28" enable-background="new 0 0 28 28" xml:space="preserve">
<path d="M27.825,4.783c0-2.427-2.182-4.608-4.608-4.608H4.783c-2.422,0-4.608,2.182-4.608,4.608v18.434
c0,2.427,2.181,4.608,4.608,4.608H14V17.379h-3.379v-4.608H14v-1.795c0-3.089,2.335-5.885,5.192-5.885h3.718v4.608h-3.726
c-0.408,0-0.884,0.492-0.884,1.236v1.836h4.609v4.608h-4.609v10.446h4.916c2.422,0,4.608-2.188,4.608-4.608V4.783z" />
</svg>
</span>
<span class="text">Facebook</span>
</a>
JS:
$('.rrssb-buttons li a').click(function(){
var url = "ajax/salvarCompartilhamento.php";
var redesocial = $(this).attr('rede-social');
$.ajax({
type: 'post',
data: {
'rede_social' : redesocial,
},
url: url,
cache: false,
dataType: 'html',
timeout: 120000,
async:false,
success: function(link){
if(link != 'erro'){
sucesso = true;
}
}
});
if(sucesso){
var t = 600;
var i = 450;
var h = ($(window).width()-t)/2;
var n = ($(window).height()-i)/2;
var o = $(this).attr('href') + link;
var w = "status=1,width="+t+",height="+i+",top="+n+",left="+h;
window.open(o,"share",w);
}
});
PHP:
include_once '../includes/constantes.php';
include_once __CLASS_FOLDER__.'/Teste.class.php';
if(!empty($_POST)){
$dados = $_POST;
} else if(!empty($_GET)) {
$dados = $_GET;
} else {
die('Acesso não autorizado');
}
$teste = new Teste();
$salvado = $teste->salvarCompartilhamento($dados);
if(is_numeric($salvado)){
echo "&ss=$salvado";
} else {
echo 'erro';
}