Add a Javascript File to BigCommerce Template - javascript

I am attempting to add a javascript file to a BigCommerce template that will enable a function needed. I am not familiar with BigCommerce but was contracted to add this functionality.
How do I add a javascript file to a BigCommerce template?
I tried create a custom folder like so:
/template/_custom/my-javascript-file.js
but when I insert that file path into the template it throws a 404 error IE:
<script type="text/javascript" src="/template/_custom/my-javascript-file.js"></script>
How do I add an external javascript file to a BigCommerce Template?

First you need to upload your JavaScript file via WebDav. I would add it to /templates/js. If this folder doesn't exist, create it.
The file path would be:
<script type="text/javascript " src="/templates/__custom/is/my-javascript-file.is"></script>
Note that __custom does not actually exist in the folder structure.

Upload your javascript to js folder
Use webdav bro and copy the HTTP URL like this one --> http://store-d17df.mybigcommerce.com/js/jquery.fitvids.js
or the big commerce way--> < script src="%%GLOBAL_TPL_PATH%%/js/common.js">

Related

JavaScript path doesn't load on Live Server extension (VS Code)

HTML and CSS files are working perfectly on my live server. But every time I lead to a .js script it will not be shown on my live server. If I try to load the .js file directly through the URL it shows "Cannot GET /line.js". I already tried out everything I've found on the internet but it's still not working. Here are the points I checked/did:
Installed Code Runner
Installed Node.js = node.js system path done
Settings = Live Server Config = specified browser
"liveServer.settings.CustomBrowser": "chrome" on JSON settings
.js file is in a separate folder and accessed via <script src="line.js"></script> on index.html
Chrome is set as default browser on my system
Thanks for your inputs.
If the js file is in a separate folder, you need to provide the exact route to the folder in the script tag, since in the current form it is trying to find the js file in the root directory. The script tag should look like this:
<script src="FOLDER_NAME/line.js"></script>
It's possible that your javascript file is being loaded before the HTML page is rendered. You can try adding "defer" to your script tag like this:
<script src="demo_defer.js" defer></script>

To unset a javascript file in contao

I have got a javascript file which is in core folder and I want to unset that file without editing the core. I haved added
$GLOBALS['TL_JAVASCRIPT'][] = 'system/modules/lazy-images/assets/lazysizes-gh-pages/lazysizes.min.js|static';
in my template file. And this file got minimized and is present in assets folder. But the same file is present in head tag.
<script src="system/modules/lazy-images/assets/lazysizes-gh-pages/lazysizes.min.js" async></script>
I need to unset this file. How this can be done?
This JavaScript is added via the config.php of that extension. See https://github.com/derhaeuptling/contao-lazy-images/blob/2.0.1/config/config.php
To unset it, you would simply need to search for 'system/modules/lazy-images/assets/lazysizes-gh-pages/lazysizes.min.js|async' within $GLOBALS['TL_JAVASCRIPT'] within the config.php of your own extension (wich is loaded after the lazy-images extension) and unset that array key.
However, it's probably not wise to do that. You should not combine this script with the others.

Why js file not loading when full url is entered in asp.net mvc?

I'm trying to load a js file in my mvc view. When I enter the full URL in the browser, the page can't load the js file but if I skip the view name in the URL it can. Please have a look at the following images for clarification:
I'm trying to load my js file like below:
<script type="text/javascript" src="~/Resources/dynamsoft.webtwain.initiate.js"></script>
What can be the reason? Thanks.
In first screen the site unable to get the js file path .
Better to use bundleconfig.cs to bind all js and css files.
click Here to know how to use bundleconfig in MVC

PHP code-igniter

I'm having troubles calling my external js files from my views php pages. The js files are saved in the "resources" folder in the root folder i.e "root/resources/scripts/myfile.js" just like the "root/application" and the "root/system" folder.
so in one of my php files in the views folder i am using this code:
<script type="text/javascript"
src="<?php echo base_url();?>resources/scripts/welcome.js">
and this php file is located in "root/application/views/welcome.php"
and still my page cannot link with the java script so i am stuck big time.
regards
k..
Try this:
<script src="<?= base_url('resources/scripts/myfile.js')?>"></script>
Looking at your question and the comments below your question, it seems you are using "resource" in one example and "resources" in another example.
Once fixed, view the source of the page (I use FireFox, as it makes the links clickable), search for "welcome.js". Once found, click on the link for that file. If you see javascript, it means the file is found, alternatively you will see a 404 error.
First of all check if the resource folder is available,
The java script file is available and the file naming is in the same small or capital case, and server has public permission of the file and folder.
by the way your code has missing end tag
</script>

Linking to javascript in a view subdirectory?

I have a view folder called 'HelloWorld', inside it I have another folder called 'table' with stuff inside it, I have something located here: table/media/js/jquery.js under the helloworld directory, I've set it to 'copy always' and its build action i s'Content'.
In the index of the view control I do this:
<script type="text/javascript" language="javascript" src="table/media/js/jquery.js")></script>
But for some reason it can't find it, if I try to manually go to it via the URL (i.e. http://localhost:XXXX/HelloWorld/table/media/js/jquery.js) the server still can't find it.
Any ideas how I'm supposed to make this work?
The View folder is not browsable for security reasons, then you cannot serve files like your javascript file.
See the web.config inside the View folder, the handler BlockViewHandler does this,
create a similar structure within the content folder if you need to organize files.
Assuming you have created the following folder: ~/HelloWorld/table/media/js/jquery.js where ~ is the root of your web site I would recommend you using url helkpers in order to generate proper url:
<script type="text/javascript" src="#Url.Content("~/HelloWorld/table/media/js/jquery.js")")></script>
On the other hand the Views folder is a special folder in which you should put only your MVC views and not static files such as css and javascript that are intended to be served directly on the client.

Categories