locked
Why 'Access Deny' when the 'src' of iframe is an absolute path like "ms-appx-web:///somepage.html"?

    Question

  • My iframe is like this:

    <iframe id = 'myiframe' src = "ms-appx-web:///somepage.html"></iframe>

    I want to access some element in the iframe from outside when the iframe loaded. Like this:

    var frame = document.getElementById('myiframe');
    frame.getSVGDocument(); //Access Deny.
    frame.contentWindow; //Access Deny, too.

    Or, I want to Access iframe element from the page in iframe. Like this:

    window.frameElement; //Access Deny

    I meet the same error: Access Deny.

    If I set the 'src' of iframe using a relative path. Like this:

    <iframe id = 'myiframe' src = "/somepage.html"></iframe>

    The error will disappear. Why?


    • Edited by Lattimore Monday, March 11, 2013 8:05 AM
    Monday, March 11, 2013 8:04 AM

Answers

  • This behavior is expected. When loading pages with the ms-appx-web scheme, you are indicating that the somePage.html will reference/load external content. There are certain restrictions when running packages from a "local" context v/s a "web" context. When loading the page with a relative path, you are loading the page locally meaning that you cannot reference external content from somePage.html. See this link for more information: http://msdn.microsoft.com/en-us/library/windows/apps/Hh781215.aspx.

    What exactly are you trying to do apart from trying to demonstrate the above issue? You can use the postMessage function to exchange messages between the local context and the web context. http://msdn.microsoft.com/en-us/library/windows/apps/hh441295.aspx

    • Marked as answer by Lattimore Tuesday, March 12, 2013 12:52 AM
    Monday, March 11, 2013 6:22 PM
    Moderator

All replies

  • This behavior is expected. When loading pages with the ms-appx-web scheme, you are indicating that the somePage.html will reference/load external content. There are certain restrictions when running packages from a "local" context v/s a "web" context. When loading the page with a relative path, you are loading the page locally meaning that you cannot reference external content from somePage.html. See this link for more information: http://msdn.microsoft.com/en-us/library/windows/apps/Hh781215.aspx.

    What exactly are you trying to do apart from trying to demonstrate the above issue? You can use the postMessage function to exchange messages between the local context and the web context. http://msdn.microsoft.com/en-us/library/windows/apps/hh441295.aspx

    • Marked as answer by Lattimore Tuesday, March 12, 2013 12:52 AM
    Monday, March 11, 2013 6:22 PM
    Moderator
  • Thanks. 
    Tuesday, March 12, 2013 12:52 AM