I have an ARC packaged ChromeOS application and since there are some behavioral differences between ChromeOS and Android I want it to make some JavaScript API call: chrome.power.requestKeepAwake.
After the obvious step of adding "power" permission, what I've tried to do is to change contents of app_main.html:
<!DOCTYPE html>
<!-- these are the lines I've added -->
<script type="text/javascript">
chrome.power.requestKeepAwake("display");
</script>
<!-- until here -->
<iframe src="_modules/mfaihdlpglflfgpfjcifdjdjcckigekc/main.html"></iframe>
But this lead to no changes.
I'm sure, that the request is not applied as I've tried to run the same query from Chrome console and it did the thing.
How should I manage to embed this code?
Actually, I've managed to solve this issue.
The reason for it to happen is not that the code is applied in the wrong moment or something like this, but that the code you use in the app_main.html can't contain inline JavaScript, which is insecure.
That said, the code should look like:
/app_main.html:
<!DOCTYPE html>
<script type="text/javascript" language="javascript" src="power_request.js">
</script>
<iframe src="_modules/mfaihdlpglflfgpfjcifdjdjcckigekc/main.html"></iframe>
/power_request.js:
chrome.power.requestKeepAwake("display");
Related
I have an Angular 7 CLI app which is served by ASP.NET MVC.
In Index.cshtml file I have these lines:
<script type="text/javascript" src="~/app/runtime.js"></script>
<script type="text/javascript" src="~/app/polyfills.js"></script>
<script type="text/javascript" src="~/app/scripts.js"></script>
<script type="text/javascript" src="~/app/vendor.js"></script>
<script type="text/javascript" src="~/app/main.js"></script>
Everything works fine.
However sometimes during development these files are not generated due to compilation errors etc.
I'm wondering is there a way to write a custom manual loader that will try to fetch these files and if any of these are not found will pop up a nice message to the developer.
Basically a really simple pre-loader to the application.
Any input is greatly appreciated.
In my case, what I do when it comes to altering the index.html is having a controller, which I call SpaController with an Index (default) action. Then, I load the index.html file (which is really small) and patch it with all the changes I want to apply. After being patched and downloaded on the browser, the rest of the communication is done through API REST, so it's just a small patch.
In your case, I would use that action of that controller I mentioned above and check if all the tag scripts are included. If not, you have flexibility to alter index.html and do what you want, like showing an error, or even stop the application.
I am following the "Using Play Framework with scala" tutorial. I am able to follow all the steps except the last one to use the coffeescript with jquery. I can see the javascript file getting generated, but in the browser, I am seeing this error
"ReferenceError: $ is not defined".
I am new to javascript and coffeescript,
here is my coffeescript code:
and here is the javascript as shown in the browser console
is there some syntax issue that can cause the problem? Help appreciated.
I am attaching the image, if indentation could be one of the reasons for this to fail.
add this line (depending on your version of jQuery)
<script src="#routes.Assets.at("javascripts/jquery-1.11.2.js")" type="text/javascript"></script>
to the <head> </head> section in app/views/main.scala.html .
For me, this template is loading for every page. but first you need to download jQuery and add it to your javascripts folder (under public).
In Play 2.3: Note the lib/jquery/jquery.js path. The lib folder denotes the extract WebJar assets, the jquery folder corresponds to the WebJar artifactId, and the jquery.js refers to the required asset at the root of the WebJar.
So just add
<script type="text/javascript" src="#routes.Assets.versioned("lib/jquery/jquery.js")"></script>
to the <head> </head> section in app/views/main.scala.html.
basic javascript, now everything seems crystal clear.
Just one line to include jquery in the index.scala.html to include jquery plugin.
This is my first question here so try to make my best so you can understand it clearly...
So my problem is that I want to load menus and footers from external HTML file so It would be easier later modify them. I can't use php or other server-side languages cause it's for school and I use it from usb stick.
My current code goes like this:
<head>
<title>SchoolStuff</title>
<script src="http://code.jquery.com/jquery-latest.js"></script>
</head>
<body>
<div id="header">
<p>[Stuff here]</p>
</div>
<script >
$("#header").load("/header.html #header");
</script> ...
and in the header.html it look like this:
<body>
<div id="header">
<ul>
<li> Just a Test</li>
</ul>
</div>
So do you guys have any ideas how to do this? It doesn't matter if you solve this in something else than jquery but it can't be server-side language. And IFrame doesn't work for this kind of purpose because I don't want the whole page. I just want specific parts.
EDIT: ok it looks like it just wont work in chrome (which is really weird though)
so if you have any ideas to get it work in chrome too it would be appreciated
EDIT 2: I decided to put my site online so it's easier for everyone...
This should be working:
<script >
$(function(){
$("#header p").load("header.html");
})
</script>
Without the use of server-side technologies, I don't believe this is possible. JavaScript adheres to the same origin policy, and when loading files via the file:// protocol the origin I believe is set to null.
In my testing, I'm getting the error: Origin null is not allowed by Access-Control-Allow-Origin. Which leads me to believe that you cannot load files from the local filesystem (small white lie, this may help).
I use openlike (openlike.org) but the site seems to be temporarily down. I would normally use something like this:
<script type="text/javascript" src="http://openlike.org/v1/openlike.js"></script>
<script type="text/javascript">OPENLIKE.Widget()</script>
But that isn't working. I've found the project on google code, I was wondering how I implement exactly the same thing, but from Google? Is Google code completely different from the google cdn? I.e. I can't just change the URL of that javascript file?
Google code project: http://code.google.com/p/openlike/source/browse/#svn%2Ftrunk%2Fv1%253Fstate%253Dclosed
Thanks for any help,
Dave
From the link posted, if you click on "openlike.js" and then "View raw file" you'll get exactly that:
http://openlike.googlecode.com/svn/trunk/v1/openlike.js
You can certainly link to this file. Here's what I tried and it worked fine:
<script type="text/javascript" src="http://openlike.googlecode.com/svn/trunk/v1/openlike.js" ></script>
<script type="text/javascript" >
console.log(OPENLIKE);
</script>
I don't know enough about google code and svn to tell you if that file will be there forever and won't change. I doubt that it's intended to be used a CDN. But it's probably good enough to use while openlike.org is down temporarily.
I have website A: http://dl.dropbox.com/u/3264697/calc/v2/index.html
It is working as intended, 100%.
I have website B: http://pe2kasb.net63.net/
It is not working as intended. Website B is a file for file mirror of A.
I assume then, this is something wrong with the host. Looking at the Javascript console, the error appears to be related to the host:
screenshot here http://img825.imageshack.us/img825/4782/unlednwe.png
Need I contact them, or is there something I can do...? I'm new to JQuery, and I believe that's what is the root of the issue but... i'm not sure.
You are trying to load jQuery from ../v2/media/js/jquery.js but there is no such file in the second website.
I recommend that instead of hosting JQuery yourself, you use a hosted version:
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js" type="text/javascript">
</script>
This post explains the reasons.
You have invalid jQuery path at http://pe2kasb.net63.net/
Replace
<script type="text/javascript" src="../v2/media/js/jquery.js"></script>
with
<script type="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
Also you have dataTable.js missing.
You are loading JQuery from ../v2/media/js/jquery.js which does not seem to exist...
To solve the issue and improve the speed of the website
do not store JQuery on the server, rather load it from a 3rd party (Google works well)
use JQuery minified version
To load JQuery from Google you can just use:
<script type="text/javascript" src="http://www.google.com/jsapi"></script>
<script type="text/javascript">
google.load("jquery", "1");
</script>
More information here
EDIT: note that the above automatically loads the minified version of JQuery. If, for whatever reason (?) you wanted to load the uncompressed version you could use
google.load("jquery", "1", {uncompressed:true});
Look what http://pe2kasb.net63.net/v2/media/js/jquery.js refers to.
The file does not exist.
Upload it or include it from another location.
Make sure that jQuery is correctly linked, currently jQuery is supposed to be at "../v2/media/js/jquery.js" on "http://pe2kasb.net63.net/", which means go back one folder then enter "/v2/media/js/jquery.js".