Loading external javascript in html when using TEdgeBrowser - javascript

It seems when i use TEdgeBrowser and navigate to my html file, that loading external local javascript files in that html does not work. -nothing happens
for example i have in html:
<!DOCTYPE>
<html>
<head>
</head>
<body>
<script src="test.js"></script>
</body>
</html>
And javascript file:
alert('HELLO');
It is simple example that should message me HELLO, but doesn't matter what is in javascript, it just doesn't load.
I don't get any DevTools errors.
When i run the html in normal browser for example chrome or edge on my pc, it works fine.
Also, when i have a script that is not local, but remote, then it works too. So it seems that the problem is only with local files. (I run delphi as administrator).
What could be the problem? I have delphi 10.4.2

Related

Play cannot reference external javascript

A very basic question
Cannot load external javascript resource on server
I am working on a Play framework project. I've made some basic html view with some Javascript. It works correctlly when I have my js code in the actual view.
However, when I tried moving js code to a separate file and load it using
<script> src="main.js" </script>
It works correctly when opened using plain chrome browser. However when I run it on server and it fails and chrome dev console prints the following message
GET http://localhost:9000/main.js 404 (Not Found)
I've tried setting up a GET request on targer URL but cannot pass main.js as an arguement to Ok method
def getmainJs()= Action {
Ok()
}
Is there a painless way to access the js code or do I have to go through the process of setting up the JavacriptRouter menntioned here. The app is only going to be 2 views to I kind of don't care about scalability
I created an example on how to serve a Javascript file:
Routes:
GET /foo sk.ygor.stackoverflow.q53319493.controller.ApplicationController.foo
GET /assets/*file controllers.Assets.versioned(file)
View:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<script src="#routes.Assets.versioned("main.js")"></script>
</body>
</html>

Why does Firefox DevTools' Debugger show 'loadSourceError'?

Consider this simple HTML file:
<!DOCTYPE html>
<html>
<body>
<script type="text/javascript">
alert('1');
</script>
</body>
</html>
When I enable Firefox JavaScript Debugger (via Ctrl+Shift+S), the panel shows me the following error message instead of the source code:
Error loading from source:
loadSourceError
What am I doing wrong?
My bet is that it comes from some server setting, since it works fine from another server (as well as locally), but I cannot identify any noticeable difference between both configurations (apache.conf are identical, /etc/apache2/sites-enabled/ configuration is similar, enabled modules are the same. I had the hope that installing the javascript-common debian package would help, but it does not…).
JavaScript itself is served correctly, though (even the embedded JS), and there is no loading problem for JS files.
Got it!
It seems that the debugger has issues with internationalized domain names (IDN).

How to run .hta file from within .html file w/o asking to download it

I want to run .hta file from within .html file w/o the browser asking to download it.It should run in an iframe in the html page in the browser. The code i am using is this-
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<iframe src="app.hta">
</body>
</html>
The problem is that the browser asks to download the hta file but it want that it should run automatically.
The hta file code is this-
<html>
<head>
<title>Application Executer</title>
<HTA:APPLICATION ID="oMyApp"
APPLICATIONNAME="Application Executer"
BORDER="no"
CAPTION="no"
SHOWINTASKBAR="yes"
SINGLEINSTANCE="yes"
SYSMENU="yes"
SCROLL="no"
WINDOWSTATE="normal">
<script type="text/javascript" language="javascript">
function RunFile() {
WshShell = new ActiveXObject("WScript.Shell");
WshShell.Run("c:/app.exe", 1, false);
}
</script>
</head>
<body>
<input type="button" value="Run Notepad" onclick="RunFile();"/>
</body>
</html>
Actually you can't open a HTA within iframe even if the main app was a HTA. HTAs have their own OS windows, just like a browser or any .exe has.
What you can do, is to put your script to a regular html file. Depending on the security settings of IE, it executes the code, or ask user to allow to execute, or throws an error.
Notice also, that ActiveXs work only in Internet Explorer. And like Dark Falcon has said, allowing ActiveX execution from web would be a huge security risk. So trying to do these kind of things at a public website is not recommended.
If this is an intranet app, you can change the main app to HTA. Then you can add Run Notepad button (and the script) to the main app, or to an iframe, which has application=yes set. Also trusted sites (html) can run ActiveXs without prompting or errors.
HTAs cannot be run under the browser. They run under a special host process called mshta. Allowing opening of an HTA in a browser frame would be asking for problems, as HTAs have much higher privileges than normal web pages.

How to embed a file in html using jquery.load() in chrome

I am trying to load a txt file using jquery in Chrome. Why it does not work? I have copied this code snippet from w3schools, and all i have changed is their url.
<!DOCTYPE html>
<html>
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.8.3/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("#div1").load("http://stackoverflow.com/questions/15114993/how-to-embed-a-file-in-html-using-jquery-load");
alert("clicked");
});
});
</script>
</head>
<body>
<div id="div1"><h2>Let jQuery AJAX Change This Text</h2></div>
<button>Get External Content</button>
</body>
</html>
Chrome throws the following error when executing your code:
Origin null is not allowed by Access-Control-Allow-Origin.
You must:
Host your HTML code on your local web server, so that it is accessible at:
http://localhost/your_directory/index.html
Update your code to load your out.txt, placed in the same folder where your index.html file is, like this (using relative paths)...
$("#div1").load("out.txt");
...or like this (using absolute paths):
$("#div1").load("http://localhost/your_directory/out.txt");
And you are done! :-)
Ok the issue you are probably having here seems to happen allot with chrome and ajax requests. Chrome throws a security issue if running locally try putting your code on a web server, or try firefox.
Or if your on a mac you can open chrome using like this from the command line to prevent the security issue
/Applications/Google\ Chrome.app/Contents/MacOS/Google\ Chrome --allow-file-access-from-files
There are loads of posts on google if your search for "allow file access from files chrome"
Good luck

magento javascript not playing nice with jquery

I'm having a bit of a problem getting my custom JavaScript file to play nice in Google chrome when jquery is being loaded in my Magento site. This problem only seems to be appearing in Google chrome. I've tested for the problem in both Linux Ubuntu 10.10 (chrome 10.0.648.114 beta) and Windows XP (chrome 9.0.597.98). FF, Safari, IE don't seem to have this problem.
When jQuery is added to the JS files to include, my personal JS file does not work when a hard refresh is sent (force a 200 request of the js file). if I do a regular refresh (304 request of the js file) and have it load from cache, then it works.
I have gone so far as to create a dummy page outside my magento site and I'm still getting this problem when I include the JS files from the magento site. but, if I move the JS files outside the magento site it works fine?
I have caching disabled in my magento admin and to my knowledge there isn't any module or custom code/plugins that would affect JS files that are to be included.
Here is an example of my dummy page that is sitting in the root directory of my server
The only thing gearlists.js has in it, is
alert('external');
so I would expect two alert popups when I load that page. but on hard refreshes, I'm only getting one popup. "Internal".
If i turn around and do a regular refresh, both JS files are loaded from the browser cache w/ a 304 status code and I get two popups "External" then "Internal"
Does Not Work With Hard Refresh
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://VIRTUAL_SERVER_FOR_MAGENTO_SITE/catalog/js/jquery/jquery-1.5.1.js"></script>
<script type="text/javascript" src="http://VIRTUAL_SERVER_FOR_MAGENTO_SITE/catalog/js/ads/gearlists.js"></script>
<script type="text/javascript">
alert('Internal');
</script>
</head>
<body>
</body>
</html>
Always Works
In this example, if I move the JS files out of the magento virtual server and into the root directory of my server, everything always works as expected. two popups are shown w/ every page refresh
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
<html>
<head>
<title>test</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script type="text/javascript" src="http://localhost/jquery-1.5.1.js"></script>
<script type="text/javascript" src="http://localhost/gearlists.js"></script>
<script type="text/javascript">
alert('here');
</script>
</head>
<body>
</body>
</html>
Now if I remove the jquery file from my test, my custom js file always works fine whether its served from withing my magento VS or not...There is always two popups.
I'm a bit stuck on what could be causing this. Any ideas would be greatly appreciated.
OK, I figured this out. dumb mistake, but it took some time. The directory for the files were the initials for the site name js/ads/gearlists.js
turns out my adblock extension uses a regex to find the word "ads" and filtered my script out. when I adjusted the directory from ads to adsinc problem went away.
makes sense that id didn't work in linux or windows since my chrome extensions are synced.
Two tips:
You may want to install the mxperts jquery plugin extension on Magento Connect - it is free and helps debugging jquery scripts that people put on your Magento site.
Google Chrome has no known way of refreshing the cache - you can rename your js files though, then it loads new ones.

Categories