cordova window.location.href behaviour error - javascript

In my assets/www/index.html, I am trying to open html in the
/data/data/files/xyz/index.html with this javascript command:
window.location.href = cordova.file.dataDirectory + "xyz/index.html";
In the ../xyz/index.html it also included the cordova.js which exists on the same xyz directory:
<script type="text/javascript" src="cordova.js"></script>
The index.html can be loaded, but in the catlog show error like below
W/CordovaWebViewImpl﹕ Blocked (possibly sub-frame) navigation to
non-allowed URL: gap://ready
is there something wrong with my method? Is it wrong to use window.location.href to open another cordova application in the data folder ?
EDIT : I already found the root cause, that is my cordova.js in the /data/data/files/xyz/cordova.js is having different version with the one in asset folder. after i copied the same cordova js version, it can be loaded without error warning. Thanks.

You don't need to use "cordova.file.datadirectory". That's only if you use the file plugin for accessing data files, such as saving high-scores in a game or level data. You do not use the plugin for loading/unloading pages into the current webview.
You would want all of your HTML files to be in the same folder branch as your "index.html". Assume a directory structure like this:
/ index.html <!---- this is your current index.html
/ page2.html
/ js / index.js
/ xyz /index.html
All you would have to do is window.location='xyz/index.html'. However, I strongly encourage you to not replace entire pages if you're developing for iOS. It's almost a guarenteed way to get your app rejected. Try loading your pages in via AJAX using a framework like "Framework7".
NOTE: You can only view files within the webview, that are in the same folder or are children of, as your initial index.html.
EDIT: You want to load another Cordova webview application. I'd suggest still making it a child of the initial "index.html" folder. However, you might be able to write a plugin or customize the platform itself to access the other files. However, that's out of the scope of this question!

Related

How can I serve remote React app with a script tag?

We have at our company a react app (built with create-react-app) which is served today via an iframe, which works well.
A need has risen to serve the app (which is always embedded within other pages), with a script tag alone (no iframe tag).
I thought of something like:
<div id="app-placeholder"></div>
<script src="https://our-app.com/init.js"></script> // this will create a function called window.InitMyApp
<script>
InitMyApp('#app-placeholder', 'token', otherOptions)
</script>
I've tried to create init.js file in the react app's public folder. I can access the file.
From that file, how can I render the react app itself to the given selector (#app-placeholder)?
Because this file is served as-is, and doesn't get transpiled by webpack/babel, I cannot use import/jsx/require() and other stuff.
Am i on the right track?
Should I manually transpile this file?
Are there any other solutions to this rendering method?
You should try configuring the compiler with { output.library }. This should produce a compilation output that's ready for distribution, which means you can easily reference it in another document (and not need to worry about, say, transpiling/optimizing sources, because this was already performed by webpack).
Here's an example of a multi-part library produced by webpack. As you can see, the entrypoint exports are being assigned to window.

Spring Boot 2: some static resources are not loaded

I added static resources into /static/ path in spring boot application.
/static/
/css/
/images/
/js/
When page loaded some css and js files are not loaded. For example: /static/js/jquery-ui/css/no-theme/jquery-ui-1.10.3.custom.min.css loaded, but, /static/js/jquery-ui/js/jquery-ui-1.10.3.minimal.min.js and /static/css/font-icons/entypo/css/entypo.css resources are not loaded - returned 404. If I move these resources to 1 or 2 step upward in folder tree, theese resources get reachable, so I can download them with direct url. but I don't want to do this. Because they are part of some template and moving can damage theme structure.
I copied not loaded files to same folder with different name.
/static/css/font-icons/entypo/css/
entypo.css
entypo_1.css
After, deleted old version and renamed new copy as old version. I don't know why, but after doing this operation for all not loaded resources they are loaded. Now its work for me.
EDITED
It need to be cleaned and built project in such situations.
This problem occurred again when I run project without building after checking out project to another PC from SVN. Then I cleaned and built project and run. The problem did not occur after that

cannot find js file

I have stucture code like this:
I try to load javascript into php file like this:
But i have an error like this:
This is my html :
And this is another javascript:
And i try to copy paste the link, and i got an error 404 not found. How can i fix it? Thanks.
Permissions
When the host is correct, and the file is in the right place, and you have no other networking problems, you may sometimes still get a 404 because of bad file permissions. If a server does not have permission to access a file, it may send out a 404 error in response. The reason why some "Not Authorized" error is not given instead, is that this would reveal more information about the files than you, the owner of the server, may intend. The way to respond to requests for privileged files without revealing whether or not they exist is to give a 404.
On Windows, you can view and change the permissions from the File Explorer by right-clicking on the file or folder, then going to Properties -> Security -> Edit. For more information, see the notes on permissions on Microsoft's site.
File Types
Besides permissions, a server must also be configured to serve the type of file you are accessing. If files with different extensions are served, but .js files are not, check the configuration of your server to make sure that .js files aren't blacklisted (or not whitelisted, as the case may be).
Directory Location
You should also verify that the files are actually stored in the top-most directory of the web server if that's how you are accessing them. If they aren't, you may need to prefix the path with the path from the webserver root to your application directory. E.g., instead of fusioncharts/..., you may need /path/to/fusioncharts/... or ../../path/to/fusioncharts.
Other Considerations
In your particular case, you should also verify that the files inside the fusioncharts folder are actually structured the way you think. (E.g., is there really a js/[insert name here].js file inside the fusioncharts folder?
If none of that solves your problem, try to take something that is working and gradually make it more and more similar to the files that aren't working. By figuring out at which point you go from a working setup to a not working setup, you may discover the problem.
If you are referring to a file with path: /ui/new-file.js
then,
1.In html file include
<script type="text/javascript" src="/ui/new-file.js"></script>
2.In server.js or app.js whichever you have, include
app.get('/ui/new-file.js', function (req, res) {
res.sendFile(path.join(__dirname, 'ui', 'login-file.js'));
});
Assuming you are using codeigniter, you can use base_url() function to include JS files in your codeignitor view template file.
<script src="<?php echo base_url(); ?>fusioncharts/js/fusioncharts.js" type="text/javascript"></script>
codeigniter default view template is called welcome_message.php and this file is located in application/view folder.
This is how I include js files in my codeigniter projects. Hope this will help.
In the html you can write *script** in the head or in the body, but not in your file js, delete this in fusionCharts.js
<script type=text/javascript>
In fusionCharts.js write only the function without the script
If you are developing locally, try clearing your cache.
Google Chrome likes to use the cached JavaScript files instead of the real ones.
Clearing your cache should resolve the issue.

using build.phonegap.com - how to reference cordova.js on pages other than index.html?

I have a multi-page news app built on Adobe CQ5 and using build.phonegap.com to compile. I can;t figure out how to reference cordova.js from all the HTML pages.
It's easy enough to use <script src="cordova.js"></script> on index.html, but the app is structured such that each article is its own HTML file on different directories. I can't hardcode the JS reference since I need it to be <script src="../cordova.js"></script> on one file and <script src="../../cordova.js"></script> on another and so on, depending on the directory of the HTML. Not to mention the path to assets and cordova.js is also different per device.
in a nutshell the structure is roughly like this:
/www/index.html <-- referencing cordova.js through <script src="cordova.js"></script>
/www/cordova.js
/www/content/breaking-news.html <-- this page needs to reference cordova.js too
/www/content/breaking-news/breaking-news-title.html <-- this page needs to reference cordova.js too
...
etc
How should I handle this? Is single page app the only solution? I am not concerned about performance since I've set up a contentsync system which will fetch zipped delta updates over the air and apply it to the app.
Relative path, like ../cordova.js or cordova.js depends on the current location of the referencing resource, like index.html or breaking-news.html. You should rather use an absolute path: /cordova.js. It'll always reference the script from the site root, regardless the current web page path.

How do I set my relative path in a user controll that is shared

I have the following solution structure.
cabinet (folder)
cabinet.aspx
images (folder)
script (folder)
folder1
menu.js
userControl (folder)
menu.ascx
default.aspx
Inside of userControl I have menu.ascx (UserControl).
Inside of menu.ascx I am referencing several .js files. For example:
<script src="./script/folder1/menu.js"></script>
When I view the default.aspx that calls menu.ascx it works fine.
However, when I'm in the cabinet folder looking at cabinet.aspx (cabinet\cabinet.aspx) that also calls menu.ascx
<%# Register Src="../userControl/menu.ascx" TagName="menu" TagPrefix="uc2" %>
The menu code is in the source but the menu.js file is a 404
http://localhost/cabinet/script/menu-files/menu.js
It looks like it needs to go directory further out. I would of expected it to go to:
http://localhost/script/menu/menu.js
What do I need to do to accomplish this?
One of two approaches:
Anchor the script reference to the site root with an absolute reference via "/script/folder1/menu.js" (note how it starts with a forward slash). For example, <script src="/script/folder1/menu.js"></script>. This says to look at the root of the site and carry on from there.
Have the script tag runat="server" and root it to the application root via "~/script/folder1/menu.js" (note the "~/" start). For example <script runat="server" src="~/script/folder1/menu.js"></script>. This determines the site root server-side and generates the correct path accordingly.
In all cases except for when your development environment doesn't allow it (I'm showing my age there going back to WinXP for development) or you are configuring an app that will live in a virtual application sub-directory in your site, go with the first option.
I figured out that the issue was the Visual Studio Web Instance that was being fired off and the fact that there were headers that needed to be set on IIS to allow the code to work.
So essentially I installed IIS 7.5 and created a site and now I just attach to the process to do my debugging for this.
Once I got IIS setup correctly the paths that were in code worked.

Categories

Resources