I am using:
if($(this).length > 0){
alert(this.files[0].name);
}
The JS is in this HTML:
<input type="file" onchange="{JS_FROM_ABOVE}">
Works fine in Chrome but in IE I get:
Unable to get property 'name' of undefined or null reference
Any advice or workaround?
I try to test your sample code with the IE 11 browser and found that it is working fine.
Tested code:
<!DOCTYPE html>
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>
$(document).ready(function(){
});
</script>
</head>
<body>
<input type="file" onchange="if($(this).length > 0){
alert(this.files[0].name);}">
</body>
</html>
Output in IE 11 browser:
I suggest trying to run my above test code on your side to check for the result. See if it works for you.
If the issue persists then please inform us which version of the IE browser you are using for making this test? Let us know which version of the JQuery you are using for making this test. It may help to narrow down the issue.
I just try to test a very basic program in javascript but on my computer it does not work. It works on other computer but not mine. I'm launching it on chrome which has javascript activated. There is my code:
index.html
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>p5.js</title>
<link rel="stylesheet" href="style.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.0/p5.js">
</script>
<script src="script.js" type="application/javascript;version=1.7"></script>
</head>
<body>
</body>
</html>
script.js
function setup() {
createCanvas(400,400);
background(0);
var x = random(0,200);
rect(x,x,(200-x)*2,(200-x)*2);
}
function draw() {
}
In my folder I have also an asset folder which is empty and my style.css is empty. With this code I am supposed to have a black square on my screen (the canvas) but there is nothing, and when I check the console on chrome nothing is written. Moreover, the first time I launched index.html a file named debug.log appears:
debug.log
[0126/184004.266:ERROR:settings.cc(263)] Settings version is not 1
Why does this script work on other computer but not mine ?
Thanks for helping.
All of your audio your files listed in the JavaScript code MUST be named as HTTPS, not HTTP. And obviously, that means the website(s) you are linking to (including yours) must be secure. That is, you need to have your security certificates, and make sure they are activated. It's a security issue with Chrome. I hope that helps. = -)
You need to call your function:
index.html
<!DOCTYPE html>
<html lang="fr">
<head>
<meta charset="utf-8">
<title>p5.js</title>
<link rel="stylesheet" href="style.css">
<script src="https://cdnjs.cloudflare.com/ajax/libs/p5.js/0.6.0/p5.js"></script>
<script src="script.js" type="application/javascript"</script>
</head>
<body>
</body>
</html>
script.js
function setup() {
createCanvas(400,400);
background(0);
var x = random(0,200);
rect(x,x,(200-x)*2,(200-x)*2);
}
function draw() {
}
setup(); // that is a function call
I tested this on Firefox and Chrome and it works. Javascript is interpreted by your browser, it has nothing to do with your computer. If the exact setup above doesn't work for you then check here. If JS is enabled and it still doesn't work then try removing the p5.js script. If that still doesn't fix it then reinstall Chrome (or even better switch to Firefox)
The accepted answer would be correct if you were not using P5.js. But since you are, you should not call the setup() function yourself! Instead, you need to let P5.js do that for you automatically. It might work with this simple example, but you'll have other problems with e.g. draw() not being called 60 times per second. If setup() and draw() are not being called, that means you're not loading the library correctly.
You need to check your developer tools for any errors, both in the JavaScript console and in the network tab.
My guess is that you're accessing your page as a file:// URL, which can have problems. You need to run a local server and access your files that way instead.
I've been trying to use the jquery.printElement plugin but nothing happens when I click on the Print link, except for this error message in the console:
Uncaught TypeError: Cannot read property 'opera' of undefined
The code I'm using is as follows:
<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>Print</title>
</head>
<body>
<p id="content">Some text to print</p>
Print
<script src="../common/js/jquery-1.10.1.min.js"></script>
<script src="../common/js/jquery.printElement.js"></script>
<script>
$('#printIt').click(function() {
$('#content').printElement();
});
</script>
</body>
</html>
Anyone know why this is happening?
The printElement plugin uses jQuery.browser internally, and $.browser has been deprecated and removed in the version of jQuery you're using.
You have to use an older version of jQuery, or possibly the migrate plugin to make printElement work.
wrap code inside document.ready.
$(function()
{
$('#printIt').click(function()
{
$('#content').printElement();
});
});
I've this script:
<html>
<head>
<script type="text/javascript">
function init(){
var extText = window.frames.messageTxt.document.body.lastChild.lastChild.data;
extText = extText.replace(/[\r\n]/g," ");
document.forms[0].nMessage.value = extText;
}
window.onload=init;
</script>
</head>
<body>
<iframe name='messageTxt' src='lineData.txt' style='display:none'></iframe>
<form>
<textarea name='nMessage'></textarea>
</form>
</body>
</html>
This code open a file (now lineData.txt) and put it on a textarea. This code works on Firefox and IE but doesn't work on Chrome.
The problem is on
window.frames.messageTxt.document.body.lastChild.lastChild.data;
The console tell me in that line:
Uncaught TypeError: Cannot read property 'body' of undefined
How can I do to make it works on Chrome ?
If you are testing locally (eg file://C:/.../test.html) you won't be able to properly access frames/iframes in Chrome.
I get an UncaughtReferenceError: QuickRead is not defined on line 10 which is QuickRead.applyToLinks();
I am using the script from here http://www.readshout.com/quickread and I believed I followed all the directions it has to use it, yet its not working.
<!DOCTYPE html>
<html>
<head>
<title>test</title>
</head>
<body>
<script language="JavaScript" type="text/javascript" src="http://www.readshout.com/bookmarklets/quickread/quickread.js"></script>
<script>
//QuickRead.setFilter('a.my_links');
QuickRead.applyToLinks();
</script>
Give up on google<br />
ycomb exp
</body>
</html>
Works for me. You could however try to add jQuery 1.4.2 manually, as QuickRead seems to dynamically load it. Otherwise try Firebug to find the error.