Quantcast
Channel: SharePoint 2013 - Development and Programming forum
Viewing all articles
Browse latest Browse all 7589

Access page data (browser DOM) of one site from another another site page

$
0
0

Hi All,

I am facing a challenge in accessing the page content of a site from a different site (cross domain). I am using below code to pull the data from div -"total_results".

But Whenever I try to alert the div text, I get a blank alert. FYA, The text inside the div is dynamic and is being pulled by a script (to which I do not have any access). Also when I see the view source of the page (which contains the div) I do not see any text inside the div as JavaScript-created elements are created after the HTML code is parsed by the browser. But I need to get the text of the div and use it on the other page.

URL's of 2 sites look like

www.abc.test.com

www.def.test.com

CODE:

$.ajax({
                 url: 'https://www.abc.test.com/sites/Pages/test.aspx?q=((abc,%20%27%22Banking%20and%20Securities%22%27)%20OR%20(xyz,%20%27%22pqr%22%27))%20AND%20((mno,%20%27%22lmn%20Risk%opq%20(US)%22%27)%20AND%20(def%3E%272013-12-31%27))',
                method: 'GET',
                headers: {
                    'Access-Control-Allow-Origin': '*'
                },
                success: function(response, status, xhr)
                {
                    var ct = xhr.getResponseHeader("content-type") || "";
                    if (ct.indexOf('html') > -1)
                    {
                        alert("This is html");
                        alert(xhr.responseText);
                        alert(response);
                    }

                    var html = $('<div>').html(response);
                    alert(html.contents().find('#total_results').text());
                    alert(html.find("div#total_results").text);

                 }
        });

Any help in this regards is highly appreciated. Thanks in advance.

Regards,

Sairam Sripad.



Viewing all articles
Browse latest Browse all 7589

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>