Jump to content

Recommended Posts

Ok this is going to get confusing and i usally make it worse when i explain things but:

 

I have a php page (index.php) which will see if ur logged in, if ur not then it loads up

"templates/StarOne/login.htm". by doing:

 

<?php
//lines up above
require_once("templates/StarOne/login.htm");
//lines below
?>

 

The javascript files I use are in: "templates/--js/blah.js", "../--js/blahblah.js"

 

So in the html files i do:

<script src="../--js/blah.js" type="text/javascript"></script>

 

And it will run on my PC with NO PROBLEMS at all however in my index page it loads up the login.htm it wont run the script at all it just goes to the next page.

 

        --------------- MY VERSION OF TRYING TO FIX IT (FAILURE HOWEVER) ----------------------

I thought possibly instead of doing to the html files (incase it runs the file from the main directory

<script src="templates/--js/blah.js" type="text/javascript"></script>

instead of:

<script src="../--js/blah.js" type="text/javascript"></script>

 

and it still dosnt work.

 

Any ideas? (By the way all the script does right now is a validation confirm for user input fields)

 

Thank you SOOOO much in advance

 

 

 

Link to comment
https://forums.phpfreaks.com/topic/58361-require_once-javascript-files/
Share on other sites

yea but in .js file if u do:

 

<!--

//code below

 

//-->

 

 

Then if u try to go to http://www.somesite.com/somefile.js

 

and it has whats mentioned above then the html takes the whole thing as a comment, but in js it works as a file with html :P

 

----------------

 

I think that works for CSS files as well :s

No, they have to download the code in order for the browser to be able to interpret it. Everything you place on your page (HTML, CSS, Javascript, images etc.) is downloaded by the user to their cache.

nevermind i fixed it doing the require_once actally does work sorry to prove u wrong buddy =/

 

There is no way for javascript to be executed without it being downloaded to the user's browser. Javascript is ran in the browser. Not on the server. Apache/PHP have no idea what your Javascript does.

 

Look at the source to your page from a browser. You will see your javascript in the source. require_once added it.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.