【问题标题】:JavaScript not working in mPDFJavaScript 在 mPDF 中不起作用
【发布时间】:2016-07-15 04:26:35
【问题描述】:

我在 PHP 中使用 mPDF 生成 PDF。它工作正常,没有问题。 如果用户未登录,我想要什么,然后我想在警告框中显示错误,然后重定向到 index.php

但由于某种原因,我不知道它没有显示任何警报框或重定向。 JavaScript 似乎无法正常工作。

代码如下:

<?php
session_start();
$uid=$_SESSION['uid']; 
  if($uid== "" or $uid == NULL)
{

    echo '<script type="text/javascript">window.alert("Please login first to access this page."); </script>';
    echo '<script type="text/javascript">window.location.href("/index.php");</script>';
}

上面的代码是文件的顶部,现在下面我有这些用于 mPDF 的代码:

include("pdf/mpdf.php");
$mpdf=new mPDF(''); 
$stylesheet = file_get_contents('pdf/tablecss.css');
$mpdf->WriteHTML($stylesheet,1);
//==============================================================

//$mpdf->WriteHTML($html);
$mpdf->SetDisplayMode('fullpage');

$mpdf->SetWatermarkText('                        www.somewebsite.com               ');
$mpdf->watermarkTextAlpha = 0.1;
$mpdf->watermark_font = 'DejaVuSansCondensed';
$mpdf->showWatermarkText = true;

$mpdf->WriteHTML($html);

$html = '
<html>
<head>
<style>
....

【问题讨论】:

  • 我看不到 pdf 适合的地方

标签: javascript php mpdf


【解决方案1】:

我解决了这个问题。我所做的是将 mPdf 代码放入 else 中。

这样就可以了。

if($uid== "" or $uid == NULL)
{

    echo '<script type="text/javascript">window.alert("Please login first to access this page."); </script>';
    echo '<script type="text/javascript">window.location.replace("/index.php");</script>';
}else{

    mpdf code goes here

【讨论】:

    猜你喜欢
    • 2019-01-27
    • 2023-04-03
    • 1970-01-01
    • 2016-07-26
    • 2022-12-30
    • 1970-01-01
    • 1970-01-01
    • 2023-03-31
    • 2020-04-02
    相关资源
    最近更新 更多