content of dynamically created iframe is empty

前端 未结 2 1094
轻奢々
轻奢々 2021-01-11 10:26

On my localhost, I am using the following JavaScript to create an iframe with src, and add it to the document:

$(\'#preview\').html         


        
2条回答
  •  半阙折子戏
    2021-01-11 10:40

    Yes the code is forbidden because of same origin policy. Read here

    Suppose you own the domain http://www.example.com then you can probably have following results, when you call pages through iframes:

    Compared URL                               Outcome  Reason
    ---------------------------------------------------------------------------------------------
    http://www.example.com/dir/page.html       Success  Same protocol and host
    http://www.example.com/dir2/other.html     Success  Same protocol and host
    http://www.example.com:81/dir2/other.html  Failure  Same protocol and host but different port
    https://www.example.com/dir2/other.html    Failure  Different protocol
    http://en.example.com/dir2/other.html      Failure  Different host
    http://example.com/dir2/other.html         Failure  Different host (exact match required)
    http://v2.www.example.com/dir2/other.html  Failure  Different host (exact match required)
    

    Now, you are calling google.com, which is a cross domain issue upon you. To get around such a problem, JSONP can help you out. It uses open script policy for

提交回复
热议问题