I'm creating a system to get the first 4 paragraphs of a given Wikipedia page and paste them into the div id="txtTextoResposta"
of the page that the user is, but the problem I'm having is that I do not know how to do it content from another site.
My code:
function resp(){
var input = prompt();
var wiki = document.download("https://pt.wikipedia.org/w/index.php?search=" + input);
var x = wiki.getElementById("mw-content-text").getElementsByTagName("p");
var linhas = x.length > 4 ? 5 : x.length;
for (var i = 0; i < linhas; i++){
document.getElementById("txtTextoResposta").innerHTML += x[i].innerText;
}
}
I invented the document.download()
function to better illustrate what I want to do.
I also tried using jQuery, like this:
javascript: (function(e, s) {
e.src = s;
e.onload = function() {
jQuery.noConflict();
console.log('jQuery injected');
};
document.head.appendChild(e);
})(document.createElement('script'), '//code.jquery.com/jquery-latest.min.js')
$.get("https://pt.wikipedia.org/w/index.php?search=" + input, function(data) { $(".result").html(data); alert("Load was performed."); });
//Neste caso, o input tinha o valor "Kant"
But I get the following error:
XMLHttpRequest can not load link . In 'Access-Control-Allow-Origin' header is present on the requested resource. Origin ' link ' is therefore not allowed access.