How to get HTML from another page

Asked

Viewed 609 times

1

I am trying to make an extension for the chorme, that when finding a field with the html element of Cpf, it generates a Cpf and adds to the field and I have the following problem:

How can I get the html of other pages of a domain for example?

localhost.meudominio.com.br

mine popup.js

document.addEventListener('DOMContentLoaded', function() {
  var list = document.getElementsByTagName("idNumber")[0];
  list.getElementsByName("idNumber")[0].innerHTML = "44245498498";
}, false);

mine popup.html

<!doctype html>
<html>
  <head>
    <title>CPF Extension</title>
    <script src="popup.js"></script>
    <script> function randomiza(n) {
  var ranNum = Math.round(Math.random()*n);
  return ranNum;
}

function mod(dividendo,divisor) {
  return Math.round(dividendo - (Math.floor(dividendo/divisor)*divisor));
}

function gerarCPF() {
  var comPontos = false;

  var n = 9;
  var n1 = randomiza(n);
  var n2 = randomiza(n);
  var n3 = randomiza(n);
  var n4 = randomiza(n);
  var n5 = randomiza(n);
  var n6 = randomiza(n);
  var n7 = randomiza(n);
  var n8 = randomiza(n);
  var n9 = randomiza(n);
  var d1 = n9*2+n8*3+n7*4+n6*5+n5*6+n4*7+n3*8+n2*9+n1*10;
  d1 = 11 - ( mod(d1,11) );
  if (d1>=10) d1 = 0;
  var d2 = d1*2+n9*3+n8*4+n7*5+n6*6+n5*7+n4*8+n3*9+n2*10+n1*11;
  d2 = 11 - ( mod(d2,11) );
  if (d2>=10) d2 = 0;
  retorno = '';
  if (comPontos) cpf = ''+n1+n2+n3+'.'+n4+n5+n6+'.'+n7+n8+n9+'-'+d1+d2;
  else cpf = ''+n1+n2+n3+n4+n5+n6+n7+n8+n9+d1+d2;

  alert(cpf);
}

gerarCPF();
</script>
   </script>
  </head>
  <body>
    <h1>Extension</h1>
    <button id="checkPage">...</button>
  </body>
</html>

1 answer

1

Just make a request Ajax for the page, example...

$.ajax({
    url: 'dominio.html',
    type: 'GET',
    success: function(html) {
        var html= $(html.responseText); 
    }
}); 

The above example uses J-query, with javascript is the same logic but with more code.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.