gpt4 book ai didi

javascript - ASP.NET iframe 有时不更新

转载 作者:行者123 更新时间:2023-12-03 09:37:54 70 4
gpt4 key购买 nike

下面是我的简化的 .aspx 文件。有时,单击“更新预览”按钮后,包含修改后的 .pdf 文件的 iframe 会显示最新文件。但有时,需要单击几次才能使 iframe 显示最新文件。

即使我直接在新窗口中重定向到该文件,.pdf 文件仍然不是最新的! (不过,它在我的服务器磁盘上)

<%@ Page Language="C#" AutoEventWireup="true" CodeBehind="WebForm1.aspx.cs" Inherits="pdfwebform.WebForm1" %>

<script runat="server">
void download_Click(object sender, EventArgs e)
{
Response.Redirect("http://dev-db-02/pdf/catalog.pdf");
}

void Button1_Click(object sender, EventArgs e)
{
string answer = call_pdf(make_new, retails_array, restypes_array, selected_kids, brands_array);
if (answer != "failed")
{
label1.Text = "Done!";
}
else
{
label1.Text = "No models meet selected criteria.";
}
}

</script>

<!DOCTYPE html>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
<title>Generate PDF Catalog</title>
<link href="theme.css" rel="stylesheet" type="text/css" />
<!--
<style type="text/css">
.auto-style1 {
width: 100%;
height: 105px;
}
.auto-style2 {
width: 557px;
}
</style>
-->
<style type="text/css">
.auto-style1 {
width: 84%;
}
.auto-style2 {
text-align: left;
width: 87px;
}
.auto-style3 {
text-align: left;
width: 486px;
}
</style>
</head>
<body>
<script type="text/javascript">
function appear() {
document.getElementById("preview").style.display = 'block';
}
</script>

<script type="text/javascript">
function updatepreview() {
if (document.getElementById("label1").innerHTML != "") {
var iframe = document.getElementById("preview1");
iframe.src = iframe.src;
iframe.src = iframe.src;
iframe.src = iframe.src;
}
else{
document.getElementById("label1").innerHTML = "Please Wait...";
}
}
</script>

<script type="text/javascript">
function update_iframe() {
var iframe = document.getElementById("preview1");
iframe.src = iframe.src;
iframe.src = iframe.src;
iframe.src = iframe.src;
}
</script>

<script type="text/javascript">
function dot() {
if (document.getElementById("label1").innerHTML == "d") {
document.getElementById("label1").innerHTML = "nope";
}
else {
document.getElementById("label1").innerHTML = "d";
}
}
</script>

<h1>Generate PDF Catalog</h1>
<form id="form1" runat="server">
<!-- <embed id="preview" src="http://dev-db-02/pdf/catalog.pdf" width="500px" height="500px" runat="server" /> -->
<iframe id="preview1" src="http://dev-db-02/pdf/catalog.pdf" width="500" height="500" runat="server"></iframe>
<!-- Add to File Feature
<asp:RadioButtonList ID="RadioButtonList1" runat="server">
<asp:ListItem Selected="True" Value="new">Create New PDF</asp:ListItem>
<asp:ListItem Value="old">Add to Existing PDF</asp:ListItem>
</asp:RadioButtonList>
-->
<table class="auto-style1">
<tr>
<td class="auto-style2">
<b>Retail:<br />
</b>
<asp:ListBox ID="ListBox5" runat="server" Height="45px" SelectionMode="multiple" Width="230px">
<asp:ListItem Selected="True" Value="Yes">Yes</asp:ListItem>
<asp:ListItem Value="No">No</asp:ListItem>
</asp:ListBox>
<b>
<br />
<br />
Res Type:</b><br />
<asp:ListBox ID="ListBox4" runat="server" SelectionMode="Multiple" Height="69px" Width="230px">
<asp:ListItem Selected="True" Value="OPTICAL">OPTICAL</asp:ListItem>
<asp:ListItem Value="KIDS">KIDS</asp:ListItem>
<asp:ListItem Value="SUN">SUN</asp:ListItem>
</asp:ListBox>
<br />
<br />
<b>Brand:</b><br />
<asp:ListBox ID="ListBox3" runat="server" Height="142px" Width="230px" SelectionMode="multiple" >
<asp:ListItem Selected="True" Value="'AS'">ASPIRE</asp:ListItem>
<asp:ListItem Value="'BCBG'">BCBGMAXAZRIA</asp:ListItem>
<asp:ListItem Value="'CVO'">CLEARVISION</asp:ListItem>
<asp:ListItem Value="'CH'">COLE HAAN</asp:ListItem>
<asp:ListItem Value="'DD'">DILLI DALLI</asp:ListItem>
<asp:ListItem Value="'DH'">DURAHINGE</asp:ListItem>
<asp:ListItem Value="'ET'">ELLEN TRACY</asp:ListItem>
<asp:ListItem Value="'IZOD'">IZOD</asp:ListItem>
<asp:ListItem Value="'IZX'">IZOD PERFORMX</asp:ListItem>
<asp:ListItem Value="'JMC'">JESSICA MCCLINTOCK</asp:ListItem>
<asp:ListItem Value="'JC'">JUNCTION CITY</asp:ListItem>
<asp:ListItem Value="'ME'">MARC ECKO</asp:ListItem>
<asp:ListItem Value="'OP'">OCEAN PACIFIC</asp:ListItem>
<asp:ListItem Value="'PT'">PURITI</asp:ListItem>
</asp:ListBox>
<br />
<br />
<br />



</td>
<td colspan="3">
<asp:Label id="label1" runat="server" Font-Bold="true" onchange="updatepreview()"></asp:Label>
<br />
<!-- <embed id="preview" src="http://dev-db-02/pdf/catalog.pdf" width="500px" height="500px" runat="server" /> -->
<iframe id="preview1" src="http://dev-db-02/pdf/catalog.pdf" width="500" height="500" runat="server"></iframe>
<br />

<!-- <iframe id="frame" style="display:none"></iframe> -->
<!-- <a href="javascript:download('http://dev-db-02/pdf/catalog.pdf')">download</a> -->

&nbsp;</td>
</tr>
<tr>
<td class="auto-style2">

<asp:Button id="Button1" runat="server" Font-Bold="True"
Font-Names="Verdana" Font-Size="12" OnClick="Button1_Click" OnClientClick="updatepreview()"
Text="Submit"></asp:Button>


</td>
<td class="auto-style3">

*<font size="3">Hold Control/Command
<br />
&nbsp;+ Click to select multiple</font>

</td>
<td class="auto-style3">
<font size="3">
<asp:Button ID="Button2" runat="server" Text="Update Preview" OnClientClick="update_iframe()" />

</font>

</td>
<td class="align-right">
&nbsp;</td>
</tr>
</table>

<br />
<br />
</div>
</form>
<script type="text/javascript">
function download() {
window.open("http://dev-db-02/pdf/catalog.pdf");
}
</script>
</body>
</html>

最佳答案

 void download_Click(object sender, EventArgs e)
{
Response.ContentType = "Application/pdf";
Response.AppendHeader("Content-Disposition", "attachment; filename=help.pdf");
Response.TransmitFile(Server.MapPath("~/pdf/catalog.pdf"));
Response.End();
}

在您的情况下,您将 301 响应重定向到返回文件的 url,问题是您正在使用 301 重定向,即使您正在更改磁盘文件浏览器也会返回缓存的 301 重定向(同一文件)

关于javascript - ASP.NET iframe 有时不更新,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/31270313/

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