How to reference script in HTML

Please explain how that might occur.

JavaScript script tags are as reliable as CSS link tags, or as image img tags, or any other similar tags.

3 Likes

@Paul_Wilkins,

The Javascript you helped me is located at “/scripts/stopVideo.js” and the script that uses it makes no reference to that script. So that says to me that script can see my “photo-gallery.php” page and the elements inside it.

So my thinking was, "What if another web page had elements that were found in the stopVideo.js script?

Could things misfire?

Not sure if that makes sense, and I am still trying to process how Javascript works, but that was my concern.

For the latest Javascript code I need help with, I want to make sure it only applies to elements found within a given web page.

That is incorrect. The stopVideo.js script will only be used when a webpage deliberately loads that script, for example with the script tag:

<script src="/scripts/stopVideo.js"></script>

Okay, but we never put a <script src="/scripts/stopVideo.js"></script> in my “photo-gallery.php” page to call that script, so how does it work?

In that case the script is not used by your page.

But your script works - I know this because it stops the video.

Am I losing my head?

I am losing my head…

Just realized that you told me to put the <script></script> at the BOTTOM of the <body></body>

:unhappy:

1 Like

You might have put the script inline in the HTML code, which results in it working but with no external scripting file being used. That would explain things.

No files are ever be used by a page, unless that page requests for that file to be used. Ever.