Note that there are some explanatory texts on larger screens.

plurals
  1. POInclude custom js file in with php function
    primarykey
    data
    text
    <p>I have a custom made function to include custom javascript files depending on de page viewed. This is the function: </p> <pre><code>function custom_jsinclude($php,$jsfile) { // $filename = basename($_SERVER['PHP_SELF']); if($filename === $php) { echo "&lt;script src=\"js/$jsfile\"&gt;&lt;/script&gt;\n"; } else { exit("Couldnt find file"); } } </code></pre> <p>Back in my php file I include it like this(between the head tags).</p> <pre><code>&lt;?php require_once('inc/functions.php'); custom_jsinclude("somepage.php","custom-scrollTo.js"); ?&gt; </code></pre> <p>When i load up the page the javascript file is included(checking the source). But it doesnt work.</p> <p>Then i tried the old fashion way: <code>&lt;script src="js/custom-scrollTo.js"&gt;&lt;/script&gt;</code> And is works fine...</p> <pre><code>&lt;!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"&gt; &lt;html xmlns="http://www.w3.org/1999/xhtml"&gt; &lt;head&gt; &lt;meta http-equiv="Content-Type" content="text/html; charset=utf-8" /&gt; &lt;title&gt;Welcome to my homepage&lt;/title&gt; &lt;script src="js/custom-scrollTo.js"&gt;&lt;/script&gt; &lt;script src="js/jquery-1.7.2.min.js"&gt;&lt;/script&gt; &lt;link href="css/somepage.css" rel="stylesheet" type="text/css" /&gt; &lt;/head&gt; </code></pre> <p>What am i missing here?</p> <p>The scrollTo code:</p> <pre><code>$(document).ready(function() { $("#prlmenu li").click(function(){ var indexli = $(this).index(); var indexh3 = indexli; var scrollto = $('h3:eq('+indexli+')').offset().top; $("html, body").animate({ scrollTop: scrollto +'px' },"fast"); }); $("div.backtotop").click(function() { $("html, body").animate({ scrollTop: "130px" },"fast"); }); $(window).scroll(function () { if($("html, body").scrollTop() &gt; 1510) { $("div.backtotop").fadeIn("slow"); } else { $("div.backtotop").hide(); } }); }); </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload