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

萬(wàn)千封印
TA貢獻(xiàn)1891條經(jīng)驗(yàn) 獲得超3個(gè)贊
onload將始終觸發(fā),我解決此問(wèn)題使用try catch block。當(dāng)您嘗試獲取contentDocument時(shí),它將拋出異常。
iframe.onload = function(){ var that = $(this)[0]; try{ that.contentDocument; } catch(err){ //TODO }}
- 3 回答
- 0 關(guān)注
- 5476 瀏覽
添加回答
舉報(bào)
0/150
提交
取消