Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
3.1k views
in Technique[技术] by (71.8m points)

jquery - Extracting the content of an element from an external page

We are quoting on a website rebuild that involves us taking a current website, doing a new design for it and then rebuilding it within Business Catalyst (Adobe's Content Management System).

Unfortunately the current website draws information from what I'm assuming to be a MySQL table (as the site is written in PHP) and Business Catalyst doesn't support the use of server-side languages.

Is there a way that I can extract a segment of HTML from a remote page on the web and display it on the new website using non server-side script, maybe with JQuery?

Here are some suggestions I have put forward and the reasoning behind why they aren't viable for this situation:

  1. iFrame - This came to mind first, but I'm not sure if it's possible to:
    a. Style the loaded HTML
    b. The content I want to capture is in the centre of the page - I don't know how to render the content of the iFrame starting from the top left of this container rather than the top left of the page itself.

  2. Export the content of the current MySQL table into Excel and then import it into Business Catalyst - this got shot down because the company has inventory management software on their computers that ties in with the database, meaning that it is updated upward of 10 times a day.

Any suggestions would be great.


If anyone can tag this question better for me that would appreciated as I'm having some trouble.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

You can use jQuery's load() function to load content from an external page (even a specific div on another page) into a div on the current page, like so:

$("#load_content_in_this_div").load("page.html #div_to_pull_from");

This will load content pulled from the #div_to_pull_from div on page.html into the #load_content_in_this_div div on the current page.

As for pulling content from pages on another domain, this plugin should do the trick.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...