0

I have a local webpage:

<html><head>
<script src="jquery.min.js"></script>
</head><body>
    <object id="oid" type="text/html" data="http://some-site" width="800px" height="600px" style="overflow:auto;border:5px ridge blue">
    testing
    </object>

    <script>
    $(document).ready(function(){
        $('object').ready(function() {
            setTimeout(function(){
                page = $('object').html();
                alert(page);
            }, 3000);
        });
    });
    </script>

</body></html>

The Alert function is viewing "testing" and not the HTML content loaded into the Object-tag. I need it to display the html from the loaded content. What am I doing wrong?

Peter Wirdemo
  • 498
  • 2
  • 11
  • 25
  • 2
    You probably can't, same-origin-policy and everything – adeneo Jan 06 '16 at 15:19
  • 1
    [Same Origin Policy](https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy) – epascarello Jan 06 '16 at 15:20
  • Well, the content is loaded perfectly fine. Can't I access the HTML then? Is that a client-side browser limit? – Peter Wirdemo Jan 06 '16 at 15:21
  • @Plarsen it's got everything to do with security, which is why you cannot access the HTML. If you where doing anything along the lines of JSON/JSONP then yes but that is not the case here – AGE Jan 06 '16 at 15:21
  • It's a security "feature" – adeneo Jan 06 '16 at 15:22
  • Do you want a person to load your email/bank account into the iframe and read it? – epascarello Jan 06 '16 at 15:22
  • Yes. some-site is willing to send some content to the user's browser. The user's browser will show it to the user. It will not show it to some-other-site's JavaScript. It doesn't know if it can trust some-other-site with the data some-site is willing to send to the user. – Quentin Jan 06 '16 at 15:22
  • I guess I will need to fetch the HTML into a variable then, instead of into an OBJECT-tag. – Peter Wirdemo Jan 06 '16 at 15:23
  • The duplicate mark is not helping, since the answer in the origin question obviously is not working. – Peter Wirdemo Jan 06 '16 at 15:26
  • You can't get the HTML at all clientside, variable, object or what not, you have to use a serverside script. – adeneo Jan 06 '16 at 15:28
  • I was more thinking of a pure port 80 request coded in C#, not using javascript at all. That way I can to whatevver I want with the data fetched, – Peter Wirdemo Jan 06 '16 at 15:30

0 Answers0