Question

We have a page which has the option to add websites. The application should create a JavaScript code which we could include in a website which would cause hits to the other websites added in the application when a user visit a parent website.

For example, as a first step you can create the code like adding an Ajax call (if the website is https://www.google.co.in/)

<script src="http://code.jquery.com/jquery-latest.js"></script>
<script>
  $(document).ready(function () {
    $.post('https://www.google.co.in/', function(data) {

    });
  });
</script>

If the user add next site 2 there should be an Ajax call to both sites. When the user adds a site, show the code in an area from there the user can copy it.

Was it helpful?

Solution

To get around Access-Control-Allow-Origin using JavaScript you can insert an iframe on to the page with the source being the URL for the new websites added to the page including any parameters. When the iframe is inserted the request will be made to the target site. Note that these will be GET and NOT POST requests.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top