【问题标题】:Open PDF in seprate windows在单独的窗口中打开 PDF
【发布时间】:2016-08-08 05:20:19
【问题描述】:

我尝试在单独的窗口中下载/打开 PDF 文件,但当前 PDF 文件在同一窗口中打开

这就是我的尝试

<script type="text/javascript">

      //$(function sumdata() {
      function mypdf() {

          $('#tabledata').tableExport({ type: 'pdf', escape: 'false' });
          window.open(mypdf);
      }
      //});

       </script>
<a  href="#"    id="pdf" onclick="mypdf()"   style="background-color: #3399FF;color: #FFFFFF;font-weight: bold;display:none;font-size: medium;PADDING: 15px;margin: 12px;"">EXPORT TO PDF</a>

当我尝试这个window.open(mypdf,'_blank') 时显示一个错误

HTTP Error 404.0 - Not Found
The resource you are looking for has been removed, had its name changed, or is temporarily unavailable.

Most likely causes:
The directory or file specified does not exist on the Web server.
The URL contains a typographical error.
A custom filter or module, such as URLScan, restricts access to the file.

Things you can try:
Create the content on the Web server.
Review the browser URL.
Check the failed request tracing log and see which module is calling SetStatus. For more information, click here.

Detailed Error Information:
Module     IIS Web Core
Notification       MapRequestHandler
Handler    StaticFile
Error Code     0x80070002
Requested URL      http://localhost:33578/function mypdf() { $('
Physical Path      C:\Users\Administrator\Documents\MIS\chart_project\chart_project\function mypdf() { $('
Logon Method       Anonymous
Logon User     Anonymous
Request Tracing Directory      C:\Users\Administrator\Documents\CHART_PROJECT

More Information:
This error means that the file or directory does not exist on the server. Create the file or directory and try the request again.
View more information »

表格导出js 检查此链接

table export

【问题讨论】:

  • 您希望您的 PDF 文档在 PDF 查看器中打开,而不是在 Web 浏览器中打开?这是一个操作系统设置,而不是可以编码的东西。您需要打开 PDF 查看器并在其中找到一个选项,以便在浏览器中不打开。这是旧的,但你明白了:blogs.adobe.com/acrolaw/2007/08/…
  • 但是当我将项目发送给客户时,我认为他们不能更喜欢这些设置.. 我有表格并且有按钮,我只想要当我点击那个按钮然后 pdf 在新标签中打开
  • 据我所知,您无法告诉链接在新选项卡、新窗口或来自 javascript 的客户端应用程序中打开。这是在浏览器或操作系统外部决定的。

标签: jquery pdf export-to-pdf


【解决方案1】:

target 属性指定打开链接文档的位置

<a  href="#"  target="_blank"   id="pdf" onclick="mypdf()"   style="background-color: #3399FF;color: #FFFFFF;font-weight: bold;display:none;font-size: medium;PADDING: 15px;margin: 12px;"">EXPORT TO PDF</a>

否则使用

var url = "Your link";    
window.open(url, '_blank');

【讨论】:

  • 有网络表单,当我点击按钮时有按钮,然后在第二个选项卡中打开相同的网络表单,在第一个选项卡中打开 pdf
  • 试试这个 window.open(url, '_blank');
  • 用“你的链接”替换我添加的链接? "
  • 我想我已经说过,当我尝试这个时会显示一个错误
  • 在没有任何脚本的情况下试试这个
【解决方案2】:

表格导出似乎不支持在新页面中打开选项。默认情况下,此插件使用 window.open 函数但未指定目标:

defaults.type == 'csv' || defaults.type == 'txt'
window.open('data:application/'+defaults.type+';filename=exportData;' + base64data);
...
defaults.type == 'sql'
window.open('data:application/sql;filename=exportData;' + base64data);
.....

您可以尝试扩展默认行为并为窗口添加目标选项。使用您正在使用的代码,它永远不会打开一个新窗口,因为此行为是在插件中完成的,而不是在您调用它的地方。

编辑

var defaults = {
                        separator: ',',
                        ignoreColumn: [],
                        tableName:'yourTableName',
                        type:'csv',
                        pdfFontSize:14,
                        pdfLeftMargin:20,
                        escape:'true',
                        htmlContent:'false',
                        consoleLog:'false',
                        // add the target to the options
                        target:'_blank'
                };

然后将其添加到所有 window.open 调用中:

 window.open('data:application/'+defaults.type+';filename=exportData;' + base64data,
 defaults.target);

这个没有测试,需要在tableExport.js中添加

【讨论】:

  • 我在哪里添加目标选项?在表导出中?
  • 您可以将其添加到tableexport中的默认选项中,并将其传递给js文件中的window.open函数
  • 这个在同一页打开:(
猜你喜欢
  • 2023-04-01
  • 2014-11-06
  • 2020-04-27
  • 1970-01-01
  • 2014-07-01
  • 1970-01-01
  • 2014-05-10
  • 1970-01-01
  • 2013-03-07
相关资源
最近更新 更多