I have this code:
jQuery(document).ready(function( $ ){
var magyar = $(".lang-item-hu a").attr("href");
$("#magyar").attr("href", magyar);
var angol = $(".lang-item-en a").attr("href");
$("#angol").attr("href", angol);
});
on my site. It works well on desktop Chrome, but doesn't work on Android Chrome.
Why? And what could be the remedy for this symptom?
Question edit/update:
On my desktop I use the latest version of Chrome 95.0.4638.69 / 64 bits on Windows 11 Pro ver: 21H2
On my mobile I also use the currently updated version of Chrome: 95.0.4638.50 on Android 11, One UI-version: 3.1
There are no related error messages on the desktop version.
I don't seem to find a debugger on Android's Chrome...
2nd edit (the solution):
No, the browser is fine.
I just had to change the id-s to classes, like so:
jQuery(document).ready(function( $ ){
var magyar = $(".lang-item-hu a").attr("href");
$(".ma").attr("href", magyar);
var angol = $(".lang-item-en a").attr("href");
$(".an").attr("href", angol);
});
...but I don't quite know why this worked. Anyone who knows leave an answer below. Thank you in advance!
One of my suggestion is try with .prop() Instead of .attr()
jQuery(document).ready(function( $ ){
var magyar = $(".lang-item-hu a").attr("href");
$("#magyar").attr("href", magyar);
var angol = $(".lang-item-en a").attr("href");
$("#angol").attr("href", angol);
});
Changed to
jQuery(document).ready(function( $ ){
var magyar = $(".lang-item-hu a").prop("href");
$("#magyar").prop("href", magyar);
var angol = $(".lang-item-en a").prop("href");
$("#angol").prop("href", angol);
});
More Details, pease check this link: https://stackoverflow.com/a/5876747/3073842
Similar Question: jquery attr() not working on mobile - Android - Chrome
No, the browser is fine.
I just had to change the id-s to classes, like so:
jQuery(document).ready(function( $ ){
var magyar = $(".lang-item-hu a").attr("href");
$(".ma").attr("href", magyar);
var angol = $(".lang-item-en a").attr("href");
$(".an").attr("href", angol);
});
...but I don't quite know why this worked. Anyone who knows leave an answer below. Thank you in advance!
Related
I want to program a "talking clock" for my blind father and I have an very old laptop, 768 RAM. I have tried many different things, from making an app on android with kivy, without any success, because on my laptop (a different one) seems to work like a charm but when I'm "buildoze" it just doesn't play any mp3. I've tried some answers provided on SO with no success. Now I thought to try to install different things, like Python libraries for 2.79 and even Java on my old laptop, but seems that because Linux Mint 2.0 it's no longer supported can't install anything...
Does anyone have any suggestion if I can use that old laptop for such a thing or I can make an app for Android that plays mp3's?
I quite a noobie 😛
Thanks
Quick, dirty, and simple: install espeak and run something like the following in a cron job as often as you like:
dt=$(date +'%A, %B %d, %Y. The time is %l %M %p.'); espeak "Today is $dt"
EDIT: On reflection, It might be better to write a shell script and call that from cron. Assuming your father's only challenge is blindness, he probably doesn't need to be reminded of the date every, say, fifteen minutes. A script could speak the date every eight hours, perhaps, and the time as often as is useful.
EDIT AGAIN: Here's a script I threw together for fun. Give it a try.
#!/bin/bash
# If espeak isn't installed, complain and quit
command -v espeak > /dev/null 2>&1 ||\
{ echo -e "$0 requires espeak to be installed. Exiting..." ; exit 1; }
# ** Set variables
date_now=$(date +'%A, %B %d, %Y')
military_time=$(date +'%R') # 24-hour time
minute=$(date +'%M')
# We don't need espeak to say "zero zero" for the minutes
if [ $minute = "00" ]; then
time_now=$(date +'%l %p')
else
time_now=$(date +'%l %M %p')
fi
# Speak the date only if it's 9am or 5pm
[[ $military_time = "09:00" || $military_time = "17:00" ]] && espeak "Today is $date_now."
espeak "The time is $time_now."
Here's a speaking-clock in JS - just load it into a WebView or something - but you don't even need to package an app: just put it in a HTML page with a PWA manifest and save that as a home-screen icon so it will work while offline.
Click "Run code snippet" and then the button.
It will work in any modern web-browser available for Android and Linux desktops (except Opera and the stock (non-Chrome) Android Browser - it will also work in any modern Linux desktop environment - or any desktop OS, really.
I hope the code is self-explanatory.
It uses the Web Speech Synthesis API which is widely supported (except by the not-Google-Chrome Android Browser for some reason).
Note that it is not possible to make it play automatically or on-load (so need to click the button first to make speech synthesis work), as most browsers (including Chrome) block scripts from auto-playing sounds without user-interaction; the same applies to <video>, <audio>, etc.
Eta voila:
function sayTime() {
if( window.speechSynthesis.speaking ) return;
const now = new Date();
var tts = new SpeechSynthesisUtterance();
tts.text = "The time is now " + now.toLocaleTimeString();
window.speechSynthesis.speak( tts );
}
let timerId = null;
function toggleSpeakingClock() {
if( timerId ) {
window.speechSynthesis.cancel();
window.clearInterval( timerId );
timerId = null;
btn.textContent = "Click me to start";
}
else {
timerId = window.setInterval( sayTime, 1000 );
const btn = document.getElementById('btn');
btn.textContent = "Click me to stop";
}
}
document.addEventListener( 'DOMContentLoaded', function() {
const btn = document.getElementById('btn');
btn.disabled = !( typeof window.speechSynthesis === 'object' ) && ( window.speechSynthesis !== null );
if( btn.disabled ) btn.textContent = "Your browser doesn't support TTS";
} );
<button id="btn" onclick="toggleSpeakingClock()" disabled>Please wait...</button>
I have tried to research a solution to my problem, but I think I lack the mental capacity to fully solve it from the examples I've found!
I have a project split into 2 halves. An ESP32 to read a RFID and iButton and an android front end to run on a kiosk.
I have the ESP set to spit out the serial numbers of the device connected/tapped and this works nicely on a windows pc with system.io.ports. What i thought would be easy is actually frustratingly difficult.
I've used the usbmanager to identify the USB devices and this works:
UsbManager manager = (UsbManager)GetSystemService(Context.UsbService);
System.Diagnostics.Debug.WriteLine("Starting USB");
var DeviceList = manager.DeviceList;
foreach (var device in DeviceList.Values)
{
var Class = device.Class;
var DeviceClass = device.DeviceClass;
var DeviceId = device.DeviceId;
var DeviceName = device.DeviceName;
var DeviceProtocol = device.DeviceProtocol;
var DeviceSubClass = device.DeviceSubclass;
var Type = device.GetType();
var ManufacturerName = device.ManufacturerName;
var ProductId = device.ProductId;
var ProductName = device.ProductName;
//var SerialNumber = device.SerialNumber;
var VendorId = device.VendorId;
var Version = device.Version;
System.Diagnostics.Debug.WriteLine(DeviceName + " " + VendorId);
}
However, how do I connect to one of the serial ports? namely one called /dev/bus/usb/006/002 4292 and read the string from it?
I've looked at several nuget libraries, but I'm struggling to get my head around these.
I'd really appreciate it if anyone could help me out! I'd rather not go back to using a windows PC in the kiosk. But serial coms on windows are so simple - although windows does have plenty of its own problems :)
Thanks
Andrew
I'm trying to POST data to an external URL in my AIR for Android app to log in users. It works in the Flash Debugger on my pc, but does not work on my Android device. I have the Internet Permission set for my app. I have listeners set up for IO_ERROR and SECURITY_ERROR but neither of these are fired. It just hangs there and does nothing when I test on the device, but it works fine in the debug player!?!?
EDIT: I've already searched for answers and the closest I came was this: AS3 AIR URLLoader POST which suggest specifying a content-type in my request, but that doesn't solve my issue
EDIT: It also works when I upload it to server and add a crossdomain.xml to the requested site.
public static function login(user:String, pass:String):void
{
username = user;
var request:URLRequest = new URLRequest( "http://mysite.com/"+user+"/login.json" );
request.method = URLRequestMethod.POST;
request.contentType = 'application/x-www-form-urlencoded';
var variables:URLVariables = new URLVariables();
variables.p = pass;
request.data = variables;
var requestor:URLLoader = new URLLoader();
requestor.addEventListener( Event.COMPLETE, loginRequestComplete );
requestor.addEventListener( IOErrorEvent.IO_ERROR, httpRequestError );
requestor.addEventListener( SecurityErrorEvent.SECURITY_ERROR, httpRequestError );
requestor.load( request );
}
Well, I finally managed to nail it....
I was grabbing my username and password from two textfields created in the ide.
The username textfield was set to multiline, which caused no problems in the online or debugger versions, but added a line break to the textfield on my android device, causing my api to return 400.
Changed it to a single line textfield and problem solved.
Crazy :)
I'm using Local Storage to pass values between pages in order to create a scroll to effect (user clicks link and is scrolled to particular part of the page based on ID)
I was previously using cookies but that didn't seem to work on Android, I read that local storage was supported so switched over to that. It works completely fine when in the browser but as soon as its packaged as a native app I lose all functionality? The API states that it should be supported, any ideas?
Here's my code:
Base URL:
var storage = window.localStorage;
$("a.scroll_link").click(function(event) {
event.preventDefault();
var value = $(this).attr("id");
storage.setItem("key",value);
console.log(value);
window.location=$(this).attr("href");
});
Receiving URL:
$(function () {
var value = window.localStorage.getItem("key");
if (value != "" && value != "undefined" && value != null) {
var storage = window.localStorage;
storage.setItem("key",value);
var scroll_type = "";
if ($.browser.webkit) {
scroll_type = "body";
} else {
scroll_type = "html";
}
$(scroll_type)
.stop()
.animate({
//get top-position of target-element and set it as scroll target
scrollTop: ($("#" + value).offset().top - 25)
//scrolldelay: 1.5 seconds
}, {
duration: 1500,
complete: function () {
storage.removeItem("key");
},
});
}
});
The code works fine in the browser just not natively, any ideas?
Thanks,
Use document.addEventListener("deviceready", onDeviceReady, false) instead of $(function(){...}
http://docs.phonegap.com/en/2.5.0/cordova_events_events.md.html#deviceready
1.Glad to know you solve your first problem. As gmh04 say, I think you should replace your init event with 'deviceready' which is triggered when the app start running.
2.
You mean window.localStorage.getItem("key") return null in Receiving URL?
I do not exactly encounter a problem as what you describe. However, you may try to move your code in receiving url to the same page of base url. I have tried for times and be very sure that the localStorage will work in the same page.
I would like add that there's a bug on the 2.6.0 version of cordova.js that make localStorage don't work on Android:
https://issues.apache.org/jira/browse/CB-3063
On the 2.5.0 version it works perfectly, and it is already fix on the 2.7.0 rc.
Is there an as3 API in Air (I'm using 3.2) to access my application version ? The one I give on the App Store or Android Market ?
Yeah you can pull it directly from the application xml descriptor. Something like this should work:
var descriptor:XML = NativeApplication.nativeApplication.applicationDescriptor;
var ns:Namespace = descriptor.namespace();
var version:String = descriptor.ns::version[0];
Looks like it's different for Air 4.0
This worked for me:
var descriptor:XML = NativeApplication.nativeApplication.applicationDescriptor;
var ns:Namespace = descriptor.namespace();
var version:String = descriptor.ns::versionNumber;
var _descriptor:XML = nativeApplication.applicationDescriptor;
var ns:Namespace = _descriptor.namespace();
var version:String = _descriptor.ns::versionNumber;
This is what works for me. "descriptor" var is used in AIR 3.2 for a UIComponentDescriptor, so I couldn't use that variable name. Also, statically accessing nativeApplication (NativeApplication.nativeApplication) gave me a null pointer reference, so I just grabbed it directly.
Lastly, versionNumber is what stores the version in AIR 3.2.