Call JavaScript code from file in HTML - javascript

I'm currently trying to play a FLAC audio file in HTML and come across this website: https://www.wakamoleguy.com/2014/flac-over-webrtc-with-sipjs/
It wanted me to go download some JavaScript code and add this to the top of the html:
<script src="aurora.js"></script>
<script src="flac.js"></script>
<script src="sip.js"></script>
After that, I downloaded flac.js, aurora.js and sip.js. But the problem is that only sip.js came as a file, while the rest came as folders. I don't know if it is possible to call a folder called flac.js or if I can call the index.js inside maybe?
flac.js and aurora.js linked me to a GitHub link, and I'm not sure if I'm meant to be using the code that way they posted it. I have nearly no clue about JavaScript but only want this to work.

You have to go to "releases" page on github:
Aurora.js: https://github.com/audiocogs/aurora.js/releases
Flac.js: https://github.com/audiocogs/flac.js/releases

Related

URL of files at server are changed in page source in wordpress site

I am trying to add adsense code to a wordpress blog demonuts.com . I have put google code in the wordpress's TEXT WIDGET . But when I run the web site the url to .js, .css or .png file is changed in view page source.
For example original url to dashicon.min.css is 'http://demonuts.com/wp-includes/css/dashicons.min.css
but in view page source it is showing as ** http://demonuts.com/wp-includes/css/dashicons.min.x40477.css**
It is working for some css and js files but not for js file of google code.
Original google code in text widget : <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script>
code in view page source : <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.x40477.js"></script>
Questions
1.) From where does this x40477 is coming and why some files are still working?
2.) Google code is not working so how can I remove this x40477?
I am trying to solve this since 2 days. Plz any help is much appreciated. Thank you in advance!
Finally found the solution. There was a plugin called "W3 Total Cache", which was updating URLd. After deleting it, problem is solved.
If someone found same problem as I have, try to find plugin which is most likely to be reason for such problems.

How add Javascript in GVnix/Spring roo project

I'm developing a web application and I want add a js file in my project to use it. I tried to add in this way:
<spring:url value="/resources/scripts/gestion.js" var="gestion"/>
<script src="${gestion}" type="text/javascript"></script>
The js loads correctly, but the problem is that the page is not showing anything, if I put this code in the end of the jsp file, before of tag <div> the jquery and another js file of the project not work although I can see the content of the jsp.
Somebody can help me with this?
You should include it into src/main/webapp/WEB-INF/tags/util/load-scripts.tagx file.
This tag is used by src/main/webapp/WEB-INF/layouts/default.jspx which is used by Apache Tiles configuration file src/main/webapp/WEB-INF/layouts/layouts.xml to generate the final html output.
Good luck!

Google app engine python doesn't read js file

I built a python app on google app engine that pulls pictures from the flickr API and allows users to do cool stuff with the pictures, like drag and drop.
I have three JS files in the body:
<script src="js/jquery-1.11.0.min.js"></script>
<script src="js/jquery-ui-1.10.4.custom.min.js"></script>
<script src="js/init.js"></script>
My jQuery code is working fine but only when I write it in either of the jQuery documents. If I place the code in the init.js, the code simply doesn't work, which I find rather weird. I put the code in the jquery files because I wrote console logs on the three script files and only the init.js didn't print to the console. I am linking the files correctly and referring to the right folder and right file. The folder JS was also added to the app.yaml:
- url: /js
static_dir: js
I can just leave the code in the jQuery file but this is not what I am supposed to do. I want to fix it.Is there a specific way to use the JS file on google app engine?
Use absolute paths instead of relative when loading your JS files (add the leading slash /):
<script src="/js/jquery-1.11.0.min.js"></script>
<script src="/js/jquery-ui-1.10.4.custom.min.js"></script>
<script src="/js/init.js"></script>
I fixed it. The problem was that I named the file init.js. For some reason Firefox doesn't like that name (at least mine didn't) and didn't load the file. Chrome loaded the file without any problems. When I changed the file name to main.js, it started working in Firefix as well. I only tried this when I had exhausted all other possible options though. Such a weird behavior of Firefox.

Wordpress: can I launch a small javascript declared on the same page? Or how to upload .js file to Wordpress?

I'm completly new to wordpress. I just want to use single javascript snippet on a page. For example:
<script>
function myFunction(){
//do something
}
</script>
// a bit later
<input type="button" name="testButton" onclick="myFunction()">
And in developers console in Chrome I get an error: "Refused to execute a JavaScript script. Source code of script found within request."
I've done some research and I think that I know it's origin - it seems that I have to add an external file with my javascript code. The bad thing is, that I have literally no idea how to do it, in spite of researching for the past few hours. Maybe it's very easy and I'm missing the simple solution, but I just don't know how to upload .js file. I've bumped into some topics saying that I have to use a php function, wp_enqueue_script(), but it still needs the .js file to be uploaded to wordpress server. Do I have to upload it as Media, a page, or what? And still, if I have to upload a javascript file each single time when I want to change something, application development will be a pain in the butt...
So is there maybe an easy way to put my javascript function definition in the same file where the function is used? That would be possibly the easiest solution.
Adding external Javascript files is probably the way to go. You upload them in the same way you would do if this was a regular HTML site, (ie using FTP or something similar).
Then you can reference it in the header.php file (accesible under the Appearance -> Editor in Wordpress).
Some themes allow you to add Javascript to the top/bottom of each page, you may want to check if your theme allows that. (check the manual with the theme or their support).
Add this whole code in header.php file of your WordPress and add
<script type='text/javascript' src='http://ajax.googleapis.com/ajax/libs/jquery/1.7.1/jquery.min.js'></script>
before your code.

JS Include is not working

I have moved an large piece of JS code form my header file to it's own .js file.
I'm trying to include it with:
<script src="includes/js/test.js" type="text/javascript"></script>
The JS code is not loaded, what could be wrong?
One possible reason is that the path is wrong. Remember that the path as you've written it will be interpreted relative to the current URL. So if this code appears on a page that is accessed at
http://www.example.com/example1/index.html
then the browser will request the javascript file from
http://www.example.com/example1/includes/js/test.js
which may not be what you want. A better approach may be to use a link that is based on the root: that is, if you change it to
<script src="/includes/js/test.js" type="text/javascript"></script>
then it will always look in
http://www.example.com/includes/js/test.js
no matter where the link appears.
If I had to guess based on the information you've provided, I'd say there's probably a syntax error in the external .js file or the page isn't finding the file from the URL provided. That's usually the problem I experience when I move large pieces of code from one file to another.

Categories