I would like to display the content of a particular div element on a 3rd party website on my website, using JavaScript. I know the id of the div element I want to display. Can this be done?
Asked
Active
Viewed 3,765 times
0
-
2I do not understand your question – Mike de Klerk Nov 23 '12 at 07:16
-
simply diplay another web page div tag content into my website div tag. – Hemantvc Nov 23 '12 at 07:23
3 Answers
2
You can't do this with Javascript.
You have to download the page using a script on your server (using something like PHP), then use that downloaded data to look through its DOM, and then select the element you want.
Javascript only works on the current page showing in a browser, it can't (shouldn't) talk to other websites.

Ben
- 54,723
- 49
- 178
- 224
0
If you want to display a website in your own website then you can use iframe for that.
<div id="help"><iframe src="http://www.codeforbrowser.com" height="500px;width="600px;"></iframe></div>

defau1t
- 10,593
- 2
- 35
- 47
-
thank you ... i am try this ifram but i want to display another website div tag value in my website. – Hemantvc Nov 23 '12 at 07:29
-
iframe will load whole of the website not the particular div of that site. – defau1t Nov 23 '12 at 07:31
-
-
you can't do that in javascript. It needs a server side language to communicate with that website from where you want to get that div – defau1t Nov 23 '12 at 07:37
0
this could be possible though no trecomended:
you can load the external site into an iframe and then access the loaded frame specific element to get the value of the div you want and then putting it into your own div

Eyal Alsheich
- 452
- 4
- 12