简体   繁体   English

在javascript / html中,如何获得外部网站(例如div)的一部分并将其设置在我的网站上?

[英]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. 我正在尝试使用javascript / html进行google chrome扩展。 Currently, I'm simply trying to make a page that has a div exactly the same as another website's div. 当前,我只是试图制作一个页面,该页面的div与另一个网站的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>. 因此,例如在Google Translate中,对于以下链接: http : //translate.google.com/ ,有一个div: <div id="gog"> ... </div>而在我的HTML页面中,有一个div:name =“ output”> ...在此处模仿“ gog” div ... </ div>。 How can I copy all the contents of "gog" into "output" using javascript. 如何使用javascript将“ gog”的所有内容复制到“ output”中。 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. 请注意 ,我没有为Google翻译提供此功能,因此访问其api不是一个可行的选择。

Thanks. 谢谢。

You could have a look at jQuery's load() function: http://api.jquery.com/load/ 您可以看一下jQuery的load()函数: 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. 会将'ajax / test.html'上#container的内容加载到当前页面的#result中。

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. 获得dom对象形状的两个div( 在此处 ),然后使用innerHtml将gog的内脏移到输出的内脏。 Does that answer your question? 这是否回答你的问题?

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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