クライアントは、ユーザーがリンクをクリックして PDF をダウンロードしたときに、JavaScript トラッキング コードを実行できるようにしたいと考えています。私の解決策は、ファイルの名前をクエリ文字列としてページに渡し、ユーザーにファイルをダウンロードするように求めることです。.netコードの前にjavascriptを実行する方法はありますか?
これは、ファイルのダウンロード ページで使用しているものです。
public partial class FileTracking : System.Web.UI.Page
{
protected void Page_Load(object sender, EventArgs e)
{
string pdf = Request["pdf"] ?? string.Empty;
if (string.IsNullOrEmpty(pdf)) return;
Response.Clear();
Response.AppendHeader("content-disposition", "attachment; filename=" + pdf);
Response.ContentType = "application/octet-stream";
Response.WriteFile(pdf);
Response.Flush();
Response.End();
}
}