Wikipedia:Reference desk/Archives/Computing/2017 July 10
Computing desk | ||
---|---|---|
< July 9 | << Jun | July | Aug >> | July 11 > |
Welcome to the Wikipedia Computing Reference Desk Archives |
---|
The page you are currently viewing is an archive page. While you can leave answers for any questions shown below, please ask new questions on one of the current reference desk pages. |
July 10
[edit]Javascript coding problem (cycling images)
[edit]OK, in light of the above answer, I will post my problem here, since I am more familiar with this place.
I am trying to get two buttons to cycle through a set of images. Button A should cycle through the images in the top box, and Button B should cycle through the same images in the bottom box. But what has happened is that both buttons cycle the top box.
What do I need to do so that each button cycles its own image set?
Here is the HTML coding:
<html>
<head>
<title>Sample</title>
<script type="text/javascript" src="alpha.js"></script>
</head>
<body>
<div id="main">
<div id="content">
<div class="maintable">
<form action="none" method="post" id="basicForm">
<table border=1>
<tr>
<td><img src="image0.jpg" id="alpha" width="30px" /></td>
<td><input type="button" value="A" onclick="changeImage()" /></td>
</tr>
<tr>
<td><img src="image0.jpg" id="alpha" width="30px" /></td>
<td><input type="button" value="B" onclick="changeImage()" /></td>
</tr>
</table>
</form>
</div>
</body>
</html>
And this is the code for alpha.js:
var n = 0;
function changeImage() {
if ( n == 0 ) { document.images["alpha"].src = "image1.jpg"; n = 1; }
else
if ( n == 1 ) { document.images["alpha"].src = "image2.jpg"; n = 2; }
else
if ( n == 2 ) { document.images["alpha"].src = "image3.jpg"; n = 3; }
else
{ document.images["alpha"].src = "image0.jpg"; n = 0; }
}
(This is not going to be the end-all of the coding. But once I get through this puzzle, I think that I can continue my work without much trouble.)
Thank you. → Michael J Ⓣ Ⓒ Ⓜ 00:11, 10 July 2017 (UTC)
- You have two elements with the id of alpha - id must be unique. -- Finlay McWalter··–·Talk 00:20, 10 July 2017 (UTC)
- As a general rule, there's not much point trying to diagnose problems with HTML code when the code is invalid. Run your code through a validator like HTML Tidy routinely (before you ever look at it in the browser) and you cut out all kinds of problems, including this one. -- Finlay McWalter··–·Talk 00:22, 10 July 2017 (UTC)
- The problem is that both image tags have the same ID. There are several ways to code it, but here is how I would approach it with the HTML:
<html>
<head>
<title>Sample</title>
<script type="text/javascript" src="alpha.js"></script>
</head>
<body>
<div id="main">
<div id="content">
<div class="maintable">
<form action="none" method="post" id="basicForm">
<table border=1>
<tr>
<td><img src="image0.jpg" id="alpha1" width="30px" /></td>
<td><input type="button" value="A" onclick="changeImage1()" /></td>
</tr>
<tr>
<td><img src="image0.jpg" id="alpha2" width="30px" /></td>
<td><input type="button" value="B" onclick="changeImage2()" /></td>
</tr>
</table>
</form>
</div>
</body>
</html>
And here is how I would code the JavaScript:
var n = 0;
function changeImage1() {
if ( n == 0 ) { document.getElementById("alpha1").src = "image1.jpg"; n = 1; }
else
if ( n == 1 ) { document.getElementById("alpha1").src = "image2.jpg"; n = 2; }
else
if ( n == 2 ) { document.getElementById("alpha1").src = "image3.jpg"; n = 3; }
else
{ document.getElementById("alpha1").src = "image0.jpg"; n = 0; }
}
function changeImage2() {
if ( n == 0 ) { document.getElementById("alpha2").src = "image1.jpg"; n = 1; }
else
if ( n == 1 ) { document.getElementById("alpha2").src = "image2.jpg"; n = 2; }
else
if ( n == 2 ) { document.getElementById("alpha2").src = "image3.jpg"; n = 3; }
else
{ document.getElementById("alpha2").src = "image0.jpg"; n = 0; }
}
- Just avoid IDs in general. Use classes (even though you do something just 'once'). You'll write better code if you take the assumption that everything is an iteration over 0..n elements. Reserve IDs mostly for unique positions within your page, so that you can reach them with anchors in links, but not for JS operations. Also don't use onclick inside your HTML (it requires JS to access global variables, and current JS designs try to avoid global variables at all cost), add event handlers from the JS instead. The following is untested, but shows an approach that could be taken. This uses raw HTML/JS, it's a bit easier with jQuery. I'd probably use a few more classnames in a real life situation, since even this is making too many assumptions about the structure of a page (the usage of parentNode.parentNode, is a clear indicator of that). —TheDJ (talk • contribs) 09:32, 10 July 2017 (UTC)
<table border=1>
<tr class="carousel" data-start="1" data-end="3" data-current="1">
<td><img src="image0.jpg" id="alpha1" width="30px" /></td>
<td><input type="button" value="A" /></td>
</tr>
<tr class="carousel" data-start="1" data-end="3" data-current="1">
<td><img src="image0.jpg" id="alpha2" width="30px" /></td>
<td><input type="button" value="B" /></td>
</tr>
</table>
function step(e) {
var element = e.currentTarget; // what element was clicked
var carouselTR = element.parentNode.parentNode; // get the element for this carousel group
carouselTR.dataset.current++; // we use data attributes to keep track of size and position in carousel
if( carouselTR.dataset.current > carouselTR.dataset.end )
carouselTR.dataset.current = carouselTR.dataset.start;
img.src = "image" + carouselTR.dataset.current + ".jpg";
}
document.addEventListener( "DOMContentLoaded", function() { // once the DOM was loaded, modify it to add event handlers to our carousel buttons
var elements = document.getElementsByClassName( "carousel" );
for( int i=0; i < elements.length; i++ ) {
elements[i].getElementsByTagName('input')[0].addEventListener( "click", step );
}
} );
A site using an unsupported protocol
[edit]I suddenly cannot get to https://kpfa.org/archives/ because Chrome says "kpfa.org uses an unsupported protocol. ERR_SSL_VERSION_OR_CIPHER_MISMATCH"
What does that mean? Am I doing something wrong? Can I access the site by doing something on my end? If yes to that last one, please forget the first two. Many thanks. :) Anna Frodesiak (talk) 11:42, 10 July 2017 (UTC)
- All I can say is "it works for me" - Chrome Version 59.0.3071.115 (Official Build) (64-bit), on macOS. Have you upgraded to the latest version of Chrome? Or maybe it's just a temporary fluke - restart the browser (if in Windows, restart the computer) and try again. --Stephan Schulz (talk) 12:32, 10 July 2017 (UTC)
- Works for me with Firefox, Chrome, Internet Explorer, and Microsoft Edge. --Guy Macon (talk) 15:15, 10 July 2017 (UTC)
- Works for me, too, using Chrome on Windows 7, 64 bit edition. StuRat (talk) 17:45, 10 July 2017 (UTC)
- The error message means your browser does not support the TLS/SSL version or cipher being used by the site you're trying to connect to. First off: are you using Windows XP perchance? If so, that's probably why. Windows XP doesn't support some of the newest ciphers and hashes, and it's no longer supported by Microsoft, so it never will. Continuing to use it is very dangerous, because it has unpatched security holes; you need to switch to a supported version of Windows or another operating system. If this isn't the case, the first thing to do is ensure Chrome is updated to the latest version. If you still get this message with the latest Chrome, try a different browser; this will determine whether the issue is Chrome or something else. --47.138.161.183 (talk) 23:27, 10 July 2017 (UTC)
Thank you all. That was very helpful indeed. :) Anna Frodesiak (talk) 07:08, 11 July 2017 (UTC)
So what's the best Windows? Anna Frodesiak (talk) 07:21, 11 July 2017 (UTC)
- To overcome this problem you'll need either Windows 7, 8, or 10. I guess most would recommend Windows 10 as it's the latest version and Chrome support for Windows 7 and 8 won't last forever. If you're using XP and don't want to upgrade Windows then it's possible that you could access this site using the Firefox browser. -- zzuuzz (talk) 08:34, 11 July 2017 (UTC)
- Note that if your computer is now running XP, it becomes increasingly less likely that it supports current versions of Windows - they require increasingly more hardware resources and features of more modern processors. If you are not wedded to particular programs and workflows, you can try to install a lightweight Linux distribution. Last time I was forced to run Windows, I installed XP in a VirtualBox on top of CentOS Linux without any trouble - I suspect this might also work the other way round if you want to play it safe. But mentioning safety: XP has no support anymore, and becomes an easier and easier target for hackers. It's probably a good idea to ditch it as soon as possible... --Stephan Schulz (talk) 08:53, 11 July 2017 (UTC)
Thank you again, folks. I'll get Windows 10 tomorrow (and some new guts if needed). Many thanks! Anna Frodesiak (talk) 09:04, 11 July 2017 (UTC)
- I would get a new computer. My neighbor's computer died from a lightning strike last weekend. He was running Windows XP on an old Dell Optiplex. I purchased a new computer off Amazon with Windows 10 and a 4 year warranty for $130. Similarly, I see brand new laptops at WalMart with Windows 10 for under $150. The retail price of Windows 10 Home is $120. Why spend that much when you can replace the computer and get Windows 10 for nearly the same price. 209.149.113.5 (talk) 12:38, 11 July 2017 (UTC)
- Good point. The answer is because I'm in China. I'm having trouble just getting Windows 10 now. But thank you. :) Anna Frodesiak (talk) 07:14, 12 July 2017 (UTC)
- Zhuangongban is free and has been pushed heavily to every computer by Lenovo, Tencent, Qihoo 360, and Xiaomi, as well as by the government itself. *NOT* upgrading to Zhangongban is the problem people have had. You appear to be the rarity who cannot upgrade. 209.149.113.5 (talk) 18:05, 12 July 2017 (UTC)
- Hmmmm, I'm not sure I want a modified Win 10. And does this mean a Win 10 shipped from the West will not work in a China-made PC? Anna Frodesiak (talk) 18:45, 12 July 2017 (UTC)
- Windows 10 is not authorized in China. Zhuangongban is the authorized version of Windows 10. Microsoft released it for free and worked with multiple organizations to push it for free to everyone. At the time, China had, by far, the highest rate of pirated Windows PCs in the world. Those "free" Windows installs were laden with back doors, viruses, bots, etc... Microsoft decided that the best thing for everyone was to get everyone on an official Windows OS, not a pirated one. So, you *can* install Windows 10 from Microsoft and then install CJK support. You might have issues with the firewall. Some people who are running Windows 10 (non-Zhuangongban) have said that they have great difficulty accessing websites. Others have said there is no problem and those who say so are just trying to start a controversy. It is up to you. If you want to get pirated Windows 10, it is your fault. If you want to pay a high premium for Windows 10, you can and it may work. If you want to get Windows 10 for free, Zhuangongban is free. 209.149.113.5 (talk) 20:00, 12 July 2017 (UTC)
- Hmmmm, I'm not sure I want a modified Win 10. And does this mean a Win 10 shipped from the West will not work in a China-made PC? Anna Frodesiak (talk) 18:45, 12 July 2017 (UTC)
.apk(s)
[edit]What (or which) is the best tested 'phone booster', 'junk cleaner', 'trash cleaner', 'cache cleaner', 'clip board content cleaner', 'temporary Internet file cleaner' 'auto app killer' available?
Could you refer me to something(s) good please?
Note: DU Speed Booster cleans something when you "Uninstall" an app. I want that in an app(s) too please.
103.67.158.10 (talk) 18:26, 10 July 2017 (UTC)
- The best "Auto-app killer" is none at all. Unless you have very unusual needs, you should not be running one these programs. They're a scam. They make your phone run slower and use more battery.[1]
- As for "Cache cleaners", you don't actually need one. One is built into the OS. You can go to "Settings/Storage/Internal Storage" and tap on cache to delete all cached data from all apps. (Of course, next time you run those apps, they may be a bit slower, because they need to re-download or regenerate the data from those caches.) However for this sort of thing, I personally tend to use App Mgr III, because I happen to like the user interface. It doesn't really do anything you couldn't do with just the OS.
- ApLundell (talk) 20:53, 10 July 2017 (UTC)
Amazon Kindle screen saver
[edit]I brought an Amazon Kindle and this thing goes into a screen saver after 5 minutes. Why does an E-ink display device need a screensaver for? AFAIK there's no burn-in issue with it. And displaying a static image doesn't take any power for an E-ink device. Covfefe beans (talk) 22:52, 10 July 2017 (UTC)
- There could be a privacy issue, if you don't want everybody knowing what scandalous reading material you prefer. :-) StuRat (talk) 03:14, 11 July 2017 (UTC)
- I think it's more of a sleep/standby screen than a screensaver per se. I.E. It indicates to the user that the device in in sleep/standby mode and will not respond to touch until you've woken it up. Other people seem to agree [2] [3] [4] [5] [6] If you have a Kindle without touch, I think these devices still function differently when in sleep/standby mode but I admit I'm not certain. With ad supported Kindle devicies, it's also a way to display ads. If you have a sleep cover (I mean a proper one with a magnet to wake the device up), you should barely see the sleep screen. Nil Einne (talk) 07:16, 11 July 2017 (UTC)