如果iframe src無法加載,則會出現捕獲錯誤。錯誤: - “拒絕在框架中顯示'http://www.google.co.in/'..”我Knockout.js用來綁定iframe src標簽(這可以根據用戶進行配置)?,F在,如果用戶已配置http://www.google.com(我知道它不會在iframe中加載,這就是為什么我將它用于-ve場景)并且必須在IFrame中顯示。但它會引發錯誤: -拒絕在框架中顯示“ http://www.google.co.in/ ”,因為它將“X-Frame-Options”設置為“SAMEORIGIN”。我為iframe提供了以下代碼: -<iframe class="iframe" id="iframe" data-bind="attr: {src: externalAppUrl, height: iframeheight}">
<p>Hi, This website does not supports IFrame</p></iframe>我想要的是,如果網址無法加載。我想顯示自定義消息。 騙子在這里現在,如果我使用onload和onerror作為: -<iframe id="browse" style="width:100%;height:100%" onload="alert('Done')" onerror="alert('Failed')"></iframe>它可以正常加載w3schools.com,但不能與google.com。其次: - 如果我把它作為一個功能,并嘗試像我在我的小提琴,它不起作用。<iframe id="browse" style="width:100%;height:100%" onload="load" onerror="error"></iframe>我不知道如何讓它運行并捕獲錯誤。
3 回答

慕桂英4014372
TA貢獻1871條經驗 獲得超13個贊
onload將始終觸發,我解決此問題使用try catch block。當您嘗試獲取contentDocument時,它將拋出異常。
iframe.onload = function(){ var that = $(this)[0]; try{ that.contentDocument; } catch(err){ //TODO }}
- 3 回答
- 0 關注
- 969 瀏覽
添加回答
舉報
0/150
提交
取消