為什麼 Internet URL 在 iframe 標記中不起作用? (Why is an Internet URL not working in an iframe tag?)


問題描述

為什麼 Internet URL 在 iframe 標記中不起作用? (Why is an Internet URL not working in an iframe tag?)

我的代碼適用於本地 URL,但不適用於 Internet URL:

<div style="margin‑top: 8px; display: Block">
    <input type="text" class="form‑control input‑sm" id="Txtlink" placeholder="Enter or Paste a Link" style="width: 84%; float: left;"><a style="border‑radius: 5px; float: right" class="btn btn‑primary" onclick="isValidURL()" type="button">Add</a>
    <iframe id="urliframe" src="" width="404" height="250" scrolling="no" style="display:none;">
        <p>Your browser does not support iframes.</p>
    </iframe>
</div>

jQuery:

function isValidURL() {
    var RegExp = /(ftp|http|https):\/\/(\w+:{0,1}\w*@)?(\S+)(:[0‑9]+)?(\/|\/([\w#!:.?+=&%@!\‑\/]))?/;
    var url = document.getElementById("Txtlink").value

    if (RegExp.test(url)) {
        $(document).ready(function () {
            $("#urliframe").show();
            var loc = url;
            alert(loc);
            document.getElementById('urliframe').setAttribute('src', loc);
        });     
    }
    else {
        alert("Error");
    }
}

參考解法

方法 1:

If it's a 3rd party site, they may have a denied access by using the X‑FRAME‑OPTIONS header.

https://developer.mozilla.org/en‑US/docs/Web/HTTP/X‑Frame‑Options

If it is your site, you may need to set the correct header to allow the page to be visible within the frame.

(by solanki kaushiklysp)

參考文件

  1. Why is an Internet URL not working in an iframe tag? (CC BY‑SA 2.5/3.0/4.0)

#iframe






相關問題

IE6 iframe 渲染問題 (IE6 iframe rendering issue)

Cross Domain JavaScript parent location setting firefox error (Cross Domain JavaScript parent location setting firefox error)

Перанакіраванне ад даччынага акна да бацькоўскага ў iframe з дапамогай javascript (OAuth) (Redirecting from child window to parent to a iframe using javascript (OAuth))

Tương tác với trình phát youtube được nhúng của học viện Khan (Interacting with Khan academy's embedded youtube player)

創建文件並將其加載到 iframe (creating file and load it in iframe)

Firefox 無法訪問同一域上的 iframe 打印 (Firefox can't access iframe print on the same domain)

如何在特定情況下處理 iframe。如何處理 iframe 內容? (How to handle iframe in particular situation. How to handle iframe contents?)

使用 jQuery 按鈕單擊更改 iFrame 的 URL? (Change URL of iFrame with jQuery button click?)

如何使網頁只允許 iframe 訪問 (How to make web page only allowed accessed by iframe)

為什麼 Internet URL 在 iframe 標記中不起作用? (Why is an Internet URL not working in an iframe tag?)

Word 2007 文件啟動新窗口而不是顯示內聯 (Word 2007 files launching new window instead of displaying inline)

有沒有辦法在 <IFrame> 中嵌入網站,如果它拒絕嵌入? (Is there any way to embed a website in <IFrame>, If it is denying to be embedded?)







留言討論