Load scripts in html-file from same subdirectory (Apache) - javascript

I feel like asking the most stupid question, but i searched for a while now and could not get it figured out.
I have the following file structure under my Apache DocumentRoot:
DocRoot
- page1
- ...
- webapp
- index.html
- somescript.js
with index.html having a script tag looking like
<script src="somescript.js" type="text/javascript">
How do i configure Apache to serve https://myhostname.com/webapp so that the script get's loaded correctly? Page1 should stay accessible under https://myhostname/page1.
The current behaviour is that somescript.js does not get found, because the request is https://myhostname.com/somescript.js.
I do NOT want to set up a Virtual Host for this or edit the html file (get's generated).

Are webapp and page1 located in var/www/html? If so, probably your JS file is searched in html folder.
You have, at least, 2 solutions:
<script src="/webapp/somescript.js" type="text/javascript">
Configure virtual hosts for webapp and page1. So, you'll be able to connect to that pages via webapp.myhostname.com and page1.myhostname.com subdomens, and <script src="somescript.js" type="text/javascript"> will work for both of them, searching in their folders

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>

How can I include a .js script in Oracle Apex?

I would like to make an input mask with javascript in Oracle Apex a bit prettier. How can I do that?
Is there any way I can upload and embed a .js file?
If so, how do you do it?
Can I style whole pages with js and then upload it?
I’m confused.
Thank you
Step 1 open Shared Components and upload your .js script into static application files
Step 2 Upload the js script into Static Application Files and copy the reference, this reference works exactly the same as an URL
Step 3 In shared components open User Interface Attributes
Step 4 Paste it into Javascript / File URLS
Your script .js will be available in all your app, also you can add .css files in Cascading Style Sheets option
You can upload files to use as application or workspace resources, but for most static files (images, js libraries, etc.) you will get much faster response if you serve them from a separate web server and just put the links in your APEX code. For example, if you are using Apache HTTP or nginx as a reverse proxy for APEX you can serve them from there.
Select a page.
Click Edit Attributes.
Scroll down to HTML Header.
Enter code into HTML Header and click Apply Changes.
For example, adding the following would test a function accessible from anywhere on the current page.
<script type="text/javascript">
function test(){
window.alert('This is a test.');
}
</script>
In Oracle Application Express you can reference a .js file in the page template. This approach makes all the JavaScript in that file accessible to the application. This is the most efficient approach since a .js file loads on the first page view of your application and is then cached by the browser.
The following demonstrates how to include a .js file in the header section of a page template. Note the line script src= that appears in bold.
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>#TITLE#</title>
#HEAD#
<script src="http://myserver.myport/my_images/custom.js" type="text/javascript"></script>
</head>
<body #ONLOAD#>#FORM_OPEN#

node.js to serve web page with access to resources on node.js server

I have an html page which references a number of local script files, and in turn those script files reference other local resources. By local I mean local to the html file.
Is it possible to serve such a web page using a node.js server approach? So far as I've been able to work out so far, the node.js server can return html content, but when that is displayed in the user's browser, I can't easily see how it would be able to reference the various scripts, because the html isn't being served from a normal folder on the server, with relative access to the folders and resources around it.
Is there any way of doing this, or is it mad to even contemplate such an approach? Better just to stick the html and related resources on a standard server and be done with it?
EDIT: I should explain that the motivation for serving the html from node.js is that I'm already serving images from the node.js server, where those images are generated using the same scripts that the html will be using. So there are two ways for the user to get the same content: as a png file or as a web page, and in both methods the work is done by the same core scripts... one has an html front end and the other has a node.js front end. So it would be nice to be able to keep all the code in a single location, rather than having to duplicate stuff and have it in two places, and have to remember to update the code in the secondary location when I update it in the primary location.
EDIT to add folder structure to help debug this (see comments below):
mypage.html
myLibFile.js
/lib/*.js (various js resources including jquery)
/lib/modules/*.js (various js resources)
/lib/fonts/* (various resources)
/themes/*.js (various js resources)
In mypage.html I have:
<script type="text/javascript" src="/lib/jquery.1.9.1.min.js"></script>
<script type="text/javascript" src="/lib/libFile.js"></script>
<script type="text/javascript" src="/lib/modules/modFile.js"></script>
<link href="/lib/fonts/awesomefont.css" rel="stylesheet">
<script type="text/javascript" src="/myLibFile.js"></script>
<script type="text/javascript">
$(function () { // On DOM ready...
// ... code ...
});
</script>
and in my node.js I have attempted to set up express as follows:
self.app.use(express.static(__dirname));
self.app.use('/lib', express.static(__dirname + '/lib'));
self.app.use('/themes', express.static(__dirname + '/themes'));
Of course your relative paths will work when using your own custom built nodejs server, which can serve files, .html .css .js and such.
I assume you have some sort of public folder from where you serve your assets. If you don't use any special routing magic, and just reffer to structure of your public folder, then relative paths in your HTML, will work.
<link rel="stylesheet" href="styles/main.css">
Code above could load something like: public/styles/main.css

Javascript not found in my ASP.Net Application

I am having a problem in the location of my javascript, the location is right, but when I run it in my visual web developer 2010 express, the location can not be found, I don't know the reason why...
here is the location of my javascript:
<script src="Style/javascript/jquery-1.7.1.js" type="text/javascript"></script>
here is the error:
**Server Error in '/Maitenance' Application.**
**The resource cannot be found.**
**Description: HTTP 404. The resource you are looking for (or one of its dependencies) could have been removed, had its name changed, or is temporarily unavailable. Please review the following URL and make sure that it is spelled correctly.**
**Requested URL: /Maitenance/Maintenance/Style/javascript/jquery-1.7.1.js**
Use this... It will work
<script src="<%=Page.ResolveUrl("~")%>Style/javascript/jquery-1.7.1.js" type="text/javascript"</script>
I guess you are using a master page and your .aspx page is put in another directory. The file path you included in master page is relative to the .aspx file. It works OK when your page in the same directory with the master page.
You can include your js file using ResolveUrl:
<script src="<%=ResolveUrl("~/js/jquery.js")%>" type="text/javascript"></script>
or you can include your script in the code behind of master page:
ClientScript.RegisterClientScriptInclude("jquery", ResolveClientUrl("~/js/jquery.js"));

Can't access Javascript file

I'm using webform asp.net and C#. I linked the master page with javascript file like this
<script type="text/javascript" src="javascript/main.js"></script>
but when I'm going to inner pages inside folders.. I can't access the JavaScript file.. (404 error).I tried to solve the problem by using ResolveClientUrl but it's not work!
What's the problem?
but when I'm going to inner pages inside folders.. I can't access the JavaScript file
Since the page you're accessing is at a different level than your master page, you want to make the script path relative to the root of your application
<script type="text/javascript" src="/javascript/main.js"></script>
EDIT if that's not working, then I would keep the script tag as it is above, run it in Chrome with the developer tools / network tab open, and look at the exact address that shows up for the failed request. Then look closely at your application and see what's different / wrong.
You can do:
<script type="text/javascript" src="<%=Page.ResolveClientUrl("~/javascript/main.js") %>" />
Allows you to use ASP.NETs ~. If this doesn't work then the file doesn't exist in that directory.

Categories