SDJ SDJ - 2 years ago 109
PHP Question

How to stop a simple javascript conflict between pages?

So I have 2 pages top.php and my Currentpage.php. The top page has the newest version of Jquery and Bootstrap. The current page has code that I can't upgrade just yet. Is there a way to stop the top.php Javascript code after it loads then have the currentpage.php Javascript load?

top.php has:

<html lang="en">
<!-- Bootstrap -->
<script src="../bootstrap/jquery/1.12.2/jquery.min.js"></script>

<!-- Bootstrap Core JavaScript -->
<script src="../bootstrap/js/bootstrap.min.js"></script>
<!-- some code here for top navigation -->

Currentpage.php has this:

<script type="style/js/jquery.form-2.47.js"></script>
<script type="text/javascript" src="style/js/jquery.ui.widget.js"></script>
<script type="text/javascript" src="style/js/jquery.ui.autocomplete.js"></script>
<script src="style/js/jquery-ui-1.8.1.dialog.min.js"></script>
<script type="text/javascript" src="index.js"></script>

include "../includes/top.php";
<!-- stop the top.php code here then load the current page Javascript code -->

Answer Source

One approach may be to read in the text file (as opposed to using an include) and remove the Javascript line then write out the contents. Something like this:

$str=str_replace("<script src=\"../bootstrap/jquery/1.12.2/jquery.min.js\"></script>", "",$str);
$str=str_replace("<script src=\"../bootstrap/js/bootstrap.min.js\"></script>", "",$str);
echo $str;
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download