2016-07-15 89 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