2016-07-15 92 views
-1

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

但由于某些原因,我不知道它不显示任何警报框也不重定向。它看起来像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> 
.... 
+0

我没有看到pdf适合在哪里 – 2016-07-15 04:29:30

回答

0

我固定的。我所做的是我把mPdf代码里面。

像这样,它的工作原理。

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