在Asp.net中的iframe中显示PDF的特定页面

Ath*_*hul 8 javascript pdf asp.net iframe jquery

我有一个ASP.NET C#应用程序.我在iframe内的特定页面上显示PDF文件.我需要根据文本框值显示特定的PDF页面.我怎样才能做到这一点?

iframe代码如下所示:

<iframe runat="server" id="lobjPDFObj" height="600" width="800" > </iframe>
Run Code Online (Sandbox Code Playgroud)

以下是文本框的详细信息

<asp:TextBox ID="txtTo" runat="server" Text="1" class="page_txtbox" onfocus="synchronizePDF(this);" ></asp:TextBox>
Run Code Online (Sandbox Code Playgroud)

javascript函数的详细信息

function synchronizePDF(Field) {
            //parent.document.getElementById('lobjPDFObj').setCurrentPage(Field.value);
        var childiFrame = parent.document.getElementById('lobjPDFObj');           
        var URL = childiFrame.contentWindow.location.href;
        //var URL = childiFrame.src;               
        var pos = URL.indexOf('#page');
        if (pos < 0) pos = URL.length;
        var result = URL.substring(0, pos);
        if (URL != 'about:blank') {
            result += '#page=' + Field.value;
        }
        childiFrame.contentWindow.location.reload(true);
        childiFrame.contentWindow.location.href = result;
        //childiFrame.src = result;
        //parent.document.getElementById('lobjPDFObj').setAttribute("src", result);

        }
Run Code Online (Sandbox Code Playgroud)

但这不起作用.它在"childiFrame.contentWindow.location.href"给出错误,因为请求访问的帧具有协议"http",正被访问的帧具有"https"协议.协议必须匹配.

我怎样才能摆脱这个错误?我在网址中传递了页面号码作为参数.如何在不刷新整个内容的情况下显示新页面?

小智 3

如下所述:请求访问的帧具有“https”协议,被访问的帧具有“http”协议。协议必须匹配,此处:Error attempts to access a iframe in JavaScript iframe 可以显示来自另一端的内容,但您不能以任何方式更改它,因为这会导致安全风险。如果要更改 iframe 的内容,其源必须来自同一域(请参阅 CORS 以获取更多参考)。

另一种方法是允许其他域的跨域资源共享。为此,您需要指定特殊标头:

Access-Control-Allow-Origin: https://www.test-doc.com
Run Code Online (Sandbox Code Playgroud)

有关此主题的更多信息:http://enable-cors.org/server_aspnet.html、http : //docs.asp.net/en/latest/security/cors.html