我使用Knockout.js
来绑定iframe src
标签(这将是可配置的相对于用户).
Now, if user has configured http://www.google.com (I know it won't load in iframe, thats why I am using it for -ve scenario) and that has to be shown in IFrame. but it throws error:-
拒绝在帧中显示"http://www.google.co.in/",因为它 将‘X-Frame-Options’设置为‘SAMEORIGIN’.
I have the following code for Iframe:-
<iframe class="iframe" id="iframe" data-bind="attr: {src: externalAppUrl, height: iframeheight}">
<p>Hi, This website does not supports IFrame</p>
</iframe>
What I want is, if the URL fails to load. I want to display Custom Message. FIDDLE HERE
现在,如果我使用onload和onerror作为:-
<iframe id="browse" style="width:100%;height:100%" onload="alert('Done')" onerror="alert('Failed')"></iframe>
它可以很好地加载w3School s.com,但不能与google.com配合使用.
Secondly:- if I make it as a function and try like I have done in my fiddle, it doesn't works.
<iframe id="browse" style="width:100%;height:100%" onload="load" onerror="error"></iframe>
I don't know how should I make it run and capture the error.
Edited:- I have seen Want to call a function if iframe doesn't load or load's question in stackoverflow but it shows error for sites that can be loaded in iframe.
此外,我还调查了Stackoverflow iframe on load event个