2

I have two static pages from a user which is deployed on their servers. Currently I am making a call to their server from code behind and loading them. But now I don't want to make a code behind call. Instead I would like to load those static pages in an iframe. Links(URL's) to those static pages is stored in my web.config. using C# during init call I am copying those URL's in hidden fields and assigning them to src of iframe like below:

<script>
    var bLoaded = false;
    function LoadIframe1() {
        if (!bLoaded) {
            var iframe1 = document.getElemetById('iframe1');
            if (typeof (iframe1) != 'undefined' && iframe1 != null) {
                iframe1.src = hiddenfield.value;
                bLoaded = true;
            }
        }
    }
</script>

<iframe id="iframe1" onload="Loadframe1();" />

Now the problem is if the files are within directory of the project, it is working fine. but how can I load the files that are not in the solution directory?

Derek 朕會功夫
  • 92,235
  • 44
  • 185
  • 247
Pratik Gaikwad
  • 1,526
  • 2
  • 21
  • 44
  • The static pages in question are hosted by another server altogether by my read of the question. – J0e3gan Jan 24 '14 at 03:53
  • @J0e3gan Ahhh, you're right, he mentions URLs to the file. Will delete my comment – jammykam Jan 24 '14 at 03:58
  • Have you checked the console in your browser's developer tools for a possible error that is preventing the display of the static pages? You may be bumping into a `SAMEORIGIN` restriction. – J0e3gan Jan 24 '14 at 04:11
  • BTW, `onload="LoadIframe1();"` not `onload="Loadframe1();"`. – J0e3gan Jan 24 '14 at 04:16

2 Answers2

5

Why are you using JavaScript? Why don't you just set the src on render?

<iframe id="iframe1" src="<%= ExternalPageUrl %>" />

And in codebehind have a property to return the URL

protected String ExternalPageUrl
{
    get
    { 
        return "http://www.example.com/path/to/page-you-need.html";
    }
}
jammykam
  • 16,940
  • 2
  • 36
  • 71
1

It is hard to say for sure without more information - e.g. errors that may be reported in your browser's development tools, but you may be bumping into a SAMEORIGIN restriction.

Here is an example of how Chrome developer tools' console would report it...

Refused to display 'https://stackoverflow.com/' in a frame because it set 'X-Frame-Options' to 'SAMEORIGIN'.

...with 'http://stackoverflow.com' assigned to iframe1.src.

Regardless whether you use codebehind or JS, you need to consider this.

See the related SO community wiki question & answers for ideas how to go about it that fit your situation.

Community
  • 1
  • 1
J0e3gan
  • 8,740
  • 10
  • 53
  • 80