简体   繁体   中英

In javascript/html, how can I get a part of an external website (such as a div) and set it onto mine?

I'm trying to make a google chrome extension using javascript/html. Currently, I'm simply trying to make a page that has a div exactly the same as another website's div. So for example in Google Translate, for the following link: http://translate.google.com/ , there is a div: <div id="gog"> ... </div> and in my html page, I have a div: name="output"> ...imitate "gog" div in here... </div>. How can I copy all the contents of "gog" into "output" using javascript. Is this not possible? Any example would be great!

Note that I'm not making this for Google translate so accessing their api isn't a viable option.

Thanks.

You could have a look at jQuery's load() function: http://api.jquery.com/load/

As you can see there

$('#result').load('ajax/test.html #container');

would load the content of #container on 'ajax/test.html' into #result on the current page.

Get the two divs in the shape of dom objects ( here ) and then use the innerHtml to move the innards of gog to the innards of output. Does that answer your question?

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM