Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8767165
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 13, 20262026-06-13T16:44:28+00:00 2026-06-13T16:44:28+00:00

I would like to avoid JavaScript in my HTML/PHP-Templates. Everything is working fine as

  • 0

I would like to avoid JavaScript in my HTML/PHP-Templates. Everything is working fine as long as I don’t need a base/root-URL in my external, included JS-File.

Problem:
Does anybody know a solution to put the JS logic (code below) into an external JS file? The main problem: how to figure out the _BASE_URL_? Unfortunately its not a form where you can get the URL by the action-attribute. I dont want to compile JS/PHP-mixed files, it has to be pure JS.

Idea (too dirty): A hidden input in the top of the body-tag with id=”root_url” or a variable in the main JS file: root_url = “http://localhost/projects/project/version/”. This is prone to failure, because no file could work stand-alone.

Maybe there’s a good htaccess/mod_rewrite solution?

Notice: I dont want to get the hostname or the “real” root dir, because it has to work in subfolders as well!

Code:

<script type="text/javascript">
// document ready
$(function() {
    // function: load items
    function load_items() {
        $("#items").load("<?php echo _BASE_URL_?>/items.php");
    }

    // load items!
    load_items();
});
</script>

<!-- target div --> 
<div id="items">loading</div>

Thanks in advance!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-13T16:44:29+00:00Added an answer on June 13, 2026 at 4:44 pm

    Can i see your html structure

    function getBaseURL () {
       return location.protocol + "//" + location.hostname + (location.port && ":" + location.port) + "/";
    }
    

    if you need a path also use this

    path = window.location.pathname.split( '/' );
    console.log(path);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I would like the user to select the time in javascript and to avoid
Problem There are data gaps that need to be filled. Would like to avoid
In my web application I would like to complately avoid html and use only
I would like to build an HTML5/javascript news reader for tablets. I know HTML,
I would like to avoid the black screen between activities when the back button
I would like to avoid redistributing .NET runtime if possible with my application since
I would like to avoid pickling of certain fields in an instance of a
I would like to avoid the if statement below. Can I somehow copy the
When users preview a report I would like to avoid giving them the option
We want to swap in changes and would like to avoid having to restart

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.