0

Is it possible to get <div> Content from a another Site and put it with JS in the currect Site?

Example:

Website 1 have a Portal and want include Content from Website 2.

Website 2 have in <div id="content"></div> the required Content.

Website 1 will get the Content with JS and put it into <div id="content_here"></div>

1

2 Answers 2

2

No, this is not possible via javascript. Any request made via javascript must made be to the same domain as the originator. This is a security feature of most browsers known as the Same Origin Policy.

The only work-around is to scrape the source of the external domain via a server-side language, such as PHP or ASP.Net and then make the AJAX request to that locally.

Sign up to request clarification or add additional context in comments.

Comments

1

IF website1 & website2 from maches the same origin policy then you can access the Iframe from the JS, if you have access to both of the websites you can pass the origin policy by using JSONP for example appendHtml(html) otherwise no you cant (as fast ideas came into my mind)

hope this helps,

2 Comments

Website1 und Webseite2 habe the same origin policy. How I can create a Iframe get only the div content?
using jQuery you can use $('iframe').contents(); or Pure JS frameRef.contentWindow ? frameRef.contentWindow.document : frameRef.contentDocument where frameRef = document.getElementById('iframeID') and to create element check this link dustindiaz.com/…

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.