Forums

The forums ran from 2008-2020 and are now closed and viewable here as an archive.

Home Forums Other how to javascript on particular page not on all pages

  • This topic is empty.
Viewing 3 posts - 1 through 3 (of 3 total)
  • Author
    Posts
  • #23600
    jitendra
    Participant

    on a website project i want to use some javaScript only on some pages not on whole project. if i include js into header.php then it will render every time on every page which i don’t want. what is the best and standard method to do this?

    i’m using this format

    Header.php
    +
    content.php = index.php
    +
    footer.php

    #51252
    Jonz
    Member

    just make an include for the javascript in the header I’d say.

    So you’ll have:
    header.php
    javascript.php
    content.php and so on…

    and only include the JavaScript when you need it to be rendered

    #51256
    uba
    Member

    You can do something like this just include it in your header.

    Code:
    $pageUrl = $_SERVER[‘PHP_SELF’];
    $pageUrl = str_ireplace(“.php”, “”, $pageUrl);

    switch ($pageUrl) {
    case “page_name_1”: case “page_name_2”: case “page_name_3” :
    echo ‘‘;
    break;
    }

    What this script dose is that it checks the page name of the currently requested file and if it matches the one you want it outputs the JavaScript code.

Viewing 3 posts - 1 through 3 (of 3 total)
  • The forum ‘Other’ is closed to new topics and replies.