iframe wikipedia article without the wrapper

2019-05-19 07:14发布

问题:

I want to embed a wikipedia article into a page but I don't want all the wrapper (navigation, etc.) that sits around the articles. I saw it done here: http://www.dayah.com/periodic/. Click on an element and the iframe is displayed and links to the article only (no wrapper). So how'd they do that? Seems like JavaScript handles showing the iframe and constructing the href but after browsing the pages javascript (http://www.dayah.com/periodic/Script/interactivity.js) I still can't figure out how the url is built. Thanks.

回答1:

The periodic table example loads the printer-friendly version of the wiki artice into an iframe. http://en.wikipedia.org/wiki/Potasium?printable=yes

it's done in function click_wiki(e) (line 534, interactivity.js)

var article = el.childNodes[0].childNodes[n_name].innerHTML;
...
window.frames["WikiFrame"].location.replace("http://" + language + ".wikipedia.org/w/index.php?title=" + encodeURIComponent(article) + "&printable=yes");


回答2:

@VolkerK is right, they are using the printable version.

Here is an easy way to find out when you know the site is displaying the page in an iframe.

In Firefox right click anywhere inside the iframe, from the context menu select "This Frame" then "View frame info"

You get the info you need including the Address:

Address: http://en.wikipedia.org/w/index.php?title=Chromium&printable=yes



回答3:

The jQuery library lets you specify part of a page to retrieve by an Ajax call, with a CSS-like syntax: http://docs.jquery.com/Ajax/load



回答4:

You could always download the site and scrap it. I think everything inside <div id="bodyContent"> is the content of the article - sans navigation, header, footer, etc..

Don't forget to credit. ;)