Usamos cookies para medir audiência e melhorar sua experiência. Você pode aceitar ou recusar a qualquer momento. Veja sobre o iMasters.
Boa tarde!
Estou desenvolvendo este código com ajuda de vocês.. o esquema é o seguinte: estou usando o YQL, quero que com a entrada de um link pelo usuário e clicando no ok o código gere diversas combinações de links e mostre o valor para o usuário... mas quando tento colocar mais de uma função o YQL retorna apenas um valor.. estou fazendo algo errado que não entendi.. gostaria da ajuda de vocês se possível.. obrigado!
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
</head>
<body>
<input type="url" id="linkproduto" value="http://www.submarino.com.br/produto/120722702/smart-tv-led-65-ultra-hd-4k-curva-samsung-un65hu7200gxzd-4-hdmi-2.0-3-usb-960hz" size="100" />
<input type="hidden" id="myText" value="" size="" />
<input type="hidden" id="myText2" value="" size="" />
<input type="button" id="button" onclick="desconto1();desconto2()" value="Ok" />
<div id="preco"></div>
<div id="preco2"></div>
<div id="preco3"></div>
<div id="preco4"></div>
<p><a id="myAnchor" href=""></a></p>
<script>
var opn1 = "?opn=AFLNOVOSUB" ;
var opn2 = "?opn=COMPARADORESSUB" ;
var franq = "&franq=AFL-03-119864&AFL-03-119864" ;
var iniyql = "https://query.yahooapis.com/v1/public/yql?q=select%20*%20from%20html%20where%20url%3D%22" ;
var fimyql = "%22%20and%20xpath%3D'%2F%2Ful%5B%40class%3D%22ld%22%5D%2F%2Fstrong'&format=xml&callback=preco" ;
function desconto1() {
document.getElementById("myAnchor").href = document.getElementById("linkproduto").value;
var linklimpo = document.getElementById("myAnchor").origin + document.getElementById("myAnchor").pathname ;
document.getElementById("myText").value = iniyql + encodeURIComponent(linklimpo) + encodeURIComponent(opn1) + fimyql ;
document.getElementById("preco2").innerHTML = linklimpo + opn1 + franq
}
(function funcao1(){
'use strict';
var $head = document.querySelector('head'),
$preco = document.getElementById('preco'),
$myText = document.getElementById('myText'),
$button = document.getElementById('button');
window.preco = function funcao1(data) {
$preco.innerHTML = data.results[0];
};
function appendScript(url){
var script = document.createElement('script');
script.src = url;
script.type = 'text/javascript';
$head.appendChild(script);
return script;
}
$button.addEventListener('click', function funcao1(){
var script = appendScript($myText.value);
$preco.innerHTML = 'Carregando...';
});
}());
function desconto2() {
document.getElementById("myAnchor").href = document.getElementById("linkproduto").value;
var linklimpo = document.getElementById("myAnchor").origin + document.getElementById("myAnchor").pathname ;
document.getElementById("myText2").value = iniyql + encodeURIComponent(linklimpo) + encodeURIComponent(opn2) + fimyql ;
document.getElementById("preco4").innerHTML = linklimpo + opn2 + franq
}
(function funcao2(){
'use strict';
var $head = document.querySelector('head'),
$preco = document.getElementById('preco3'),
$myText = document.getElementById('myText'),
$button = document.getElementById('button');
window.preco3 = function(data) {
$preco.innerHTML = data.results[0];
};
function appendScript(url){
var script = document.createElement('script');
script.src = url;
script.type = 'text/javascript';
$head.appendChild(script);
return script;
}
$button.addEventListener('click', function(){
var script = appendScript($myText.value);
$preco.innerHTML = 'Carregando...';
});
}());
</script>Carregando comentários...