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.
Related
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>
I have event coded to show the event on each page of the website. Is there a way to code it so that when you need to update it, you can do it once and it will show on each page? (vs having to update HTML text on each page).
Yes, create a external JavaScript(.js) file and include it on the each page. e.g
<script src="scriptfile.js"></script>
Whenever you want to update/change, just update the js file.
Definitely. You can set up a local server and then make .php files having html code in them. You can then include these .php files in your different html files as and when required. But for all this to work, local server configuration is required(like Apache and MySQL).
On my site I have my resources folder outside of the root, for example:
/var/www/html/ is the root directory
/var/www/resources/
I currently have a config file that sets the location of the library so I can include it with php like so:
defined("LIBRARY_PATH")
or
define("LIBRARY_PATH", realpath(dirname(__FILE__) . '/library'));
which works perfectly when I use:
<?php include_once(LIBRARY_PATH . "/file.php"); ?>
but it doesn't work when trying to add Javascript files:
e.g.
<script src="../resources/library/js/test.js"></script>
links to 'www.website.com/resources/library/js/common.js'
or
<script src="<?php echo LIBRARY_PATH; ?>/js/test.js"></script>
links to 'www.website.com/var/www/resources/library/js/test.js'
neither of which work.
Any suggestions on how I can do this without having the js files in or above the root?
Your JavaScript files have to be accessible to the browser because they are executed by the browser and not by the server.
This requires that they have a URL.
Putting the files under the webroot is the standard way to give a static file a URL.
Alternatively, you could write a program (e.g. in PHP) that will read the file and then output it's content to the browser. This is more complicated and makes dealing with cache control headers more fiddly and is not recommended.
Assuming you understand what you're doing and security implications of that!..
You create the linkjs.php script that takes the relative path to the script (from some root dir, perhaps /var/www/resource/js) as a parameter, like:
<script src="/linkjs.php?p=test.js">
In your PHP script you resolve the full file path, check that it's indeed a file under the root dir (to protect against ../ in the parameter), that it's readable by you PHP user, read the content and output it into the response. Don't forget to set content type to text/javascript of course.
Ideally, you should also provide proper caching headers based on the source file modification time, but that is a topic in itself. See the guidelines in other SO questions about proper caching headers for dynamic content.
The upside is that you can do on-the-fly script minification/combining/wrapping/substitutions if you like/need.
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>
I used the script
<!--#include virtual="dontate.html" -->
to include a .html file into another .html file, but for some reason does not show up.
Any reason as to why?
I will be using WAMP and LAMP.
Thanks
Jean
This is using server-side includes. You need to set it up on your server. Despite the misleading "comment" syntax, it really has nothing to do with HTML.
if there's php on the server you can just include the html file like so
<?php include "donate.html"; ?>
A lamp stack has php so you should be set.
However, the server may not be set up to run the file through php's interpreter. You can either set it to parse whatever the extension of the file is (being the file that is doing the including) or change it to something that is already set to be parsed (home.html -> home.php)
As your using wamp/lamp I found something that will work:
creating a .htaccess file and put the following in it
Options FollowSymLinks Includes ExecCGI
AddType text/html .shtml
AddOutputFilter INCLUDES .shtml
Then change your html file extensions to .shtml (including the file that is to include a file)
So
<!--#include virtual="dontate.html" -->
Would become
<!--#include virtual="dontate.shtml" -->
This should work
NOTE:
The file is in the same directory as the file that is including it use:
<!--#include file="dontate.shtml" -->
If it is in a different directory use:
<!--#include virtual="folder/to/file/dontate.shtml" -->
Perhaps the problem is the use of virtual
The file parameter defines the included file as relative to the document path; the virtual parameter defines the included file as relative to the document root.
http://en.wikipedia.org/wiki/Server_Side_Includes
<object data="file.html" width=400 height=200"></object>
If memory serves... I recall some border issues in IE but that should be sufficient for a primitive integration.
As per the HTML spec, the only way to do this without server side scripting or server side includes is via iframes.
* note the bolded 'only'.
Guys..here is the answer
// jsfile.js
var variable=""+
"";
document.write(variable);
****include .js file in html****
thats it