问题
What I want to do is basically a div-Element containing the print-friendly version of Wikipedia articles. I used an iframe to embed articles and it works, though I cannot style the document. I guess this is because the iframe content is not on my domain and I do not have editing rights. Is there a way to apply css styling to the content after the iframe is loaded?
回答1:
You can do this with AJAX by calling the wiki api with custom query string parameters.
DEMO http://jsfiddle.net/fm0vxg32/
JS
$(document).ready(function(){
$.ajax({
type: "GET",
url: "http://en.wikipedia.org/w/api.php?action=parse&format=json&prop=text§ion=0&page=Jimi_Hendrix&callback=?",
contentType: "application/json; charset=utf-8",
async: false,
dataType: "json",
success: function (data, textStatus, jqXHR) {
var markup = data.parse.text["*"];
var blurb = $('<div></div>').html(markup);
$('#article').html($(blurb).find('p'));
},
error: function (errorMessage) {
}
});
});
CSS
#article {
// custom styling
}
来源:https://stackoverflow.com/questions/26577292/is-there-a-way-to-embed-and-style-a-wikipedia-article-in-a-website