admin管理员组

文章数量:1401384

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?

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?

Share Improve this question edited Oct 26, 2014 at 20:41 celeritas 2,2811 gold badge19 silver badges28 bronze badges asked Oct 26, 2014 at 20:01 ifthisthenthatifthisthenthat 951 gold badge2 silver badges10 bronze badges 4
  • Download it with server-side script, modify paths to css and so on, insert the result into your page. – Cheery Commented Oct 26, 2014 at 20:03
  • Thank you. Unfortunately I lack the knowledge to do the server side download. Would you use PHP for that? – ifthisthenthat Commented Oct 26, 2014 at 20:06
  • PHP, Perl, Python, .. whatever you can run on server-side. Even by wget + bash – Cheery Commented Oct 26, 2014 at 20:06
  • what about this embed.ly/provider/wikipedia (3rd party service) – andilabs Commented Oct 27, 2019 at 14:33
Add a ment  | 

1 Answer 1

Reset to default 6

You can do this with AJAX by calling the wiki api with custom query string parameters.

DEMO http://jsfiddle/fm0vxg32/

JS

$(document).ready(function(){

    $.ajax({
        type: "GET",
        url: "http://en.wikipedia/w/api.php?action=parse&format=json&prop=text&section=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
}

本文标签: javascriptIs there a way to embed and style a Wikipedia article in a websiteStack Overflow