开发者

Exclude one JS file for a particular page

I have two JS files: mail.js and prototype.js

prototype.js is from Lightbox plug-in and mail.js is validator and ajax for the contact us page.

the problem is mail.js won't work when prototype.js is load before or after it.

However I want to remove the prototype.js for contact page only where there's no need for lightbox.

I'm using php include as header. Is there a way to set th开发者_如何学运维e prototype.js as unload for the contact page only?

Thanks


In the header inlude, can't you just do an if statement like so:

if($_SERVER[’PHP_SELF’]!="contact_us.php"){
    echo '<script type="text/javascript" src="js/prototype.js"></script>';
}

Obviously replace the paths with the correct path. PHP_SELF is relative to domain, so if its in /pages/ then $_SERVER['PHP_SELF'] would equal /pages/contact_us.php

Correct answer was

if($_SERVER['REQUEST_URI']!="contact_us.php"){
    echo '<script type="text/javascript" src="js/prototype.js"></script>';
}
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜