gpt4 book ai didi

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

转载 作者:数据小太阳 更新时间:2023-10-29 04:14:34 24 4
gpt4 key购买 nike

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

iframe 代码如下所示:

<iframe runat="server" id="lobjPDFObj" height="600" width="800" > </iframe>

下面是文本框的详细信息

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

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);

}

但这行不通。它在“childiFrame.contentWindow.location.href”处给出错误,因为 请求访问的框架具有“http”协议(protocol),正在访问的框架具有“https”协议(protocol)。协议(protocol)必须匹配。

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

最佳答案

如此处所述:The frame requesting access has a protocol of "https", the frame being accessed has a protocol of "http". Protocols must match在这里:Error trying to access a iframe in JavaScript iframe 可以显示其他方面的内容,但您不能以任何方式更改它,因为这会导致安全风险。如果您想更改 iframe 的内容,它的源必须来自同一域(有关更多引用,请参阅 CORS)。

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

Access-Control-Allow-Origin: https://www.test-doc.com

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

关于javascript - 在 Asp.net 中的 iframe 中显示 PDF 的特定页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/36663859/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com