开发者

how to exclude a .js file for a particular page

my js files are included through header. i dont want to have some .js files included in certain pages, while that particula开发者_如何学运维r page is loading. is it is possible.??? help me please.....


<?php
    if (! some_condition() ) {
?>
<script …></script>
<?php
    }
?>


You could use an array of files to include.

In your main file:

$jsFiles=array('jquery.js','mylib.js','test.js');

In your header file:

foreach($jsFiles as $jsFile){
    print("<script type='text/javascript' src='$jsFile'></script>");
}

Code is not tested but that should give you the idea.


What specifically is the page? Can you just re-write the header on the one page? Or, if you use a header function, just rewrite the function like:

<?php
echo "<html>";
echo "<head>";
if (use a regexp to extract the page URL ) {
    echo "<script>  ....   </script>
    }
echo "</head>";
.........


<?php 
    if($_SERVER['PHP_SELF'] == 'page.php'){ 
?>

<script></script> 
<?php } ?>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜