Javascript countdown does not show in Opera mini - javascript

So i have this countdown script, which is works just fine almost every browser but not in opera mini. It shows a blank space.
Here is my code:
timer={
times:[],
init:false,
callback:function() { window.location.reload(); },
new:function(time)
{
timer.times[timer.times.length]=time;
document.write("<span id='timer_"+(timer.times.length-1)+"'>"+timer.format(time)+"</span>");
timer.start();
},
format:function(time)
{
days=Math.floor(time/(60*60*24));
hours=Math.floor(time%(60*60*24)/(60*60));
mins=Math.floor(time%(60*60)/60);
secs=Math.floor(time%60);
return (mins<10?"0":"")+mins+":"+(secs<10?"0":"")+secs+"";
},
ticker:function()
{
for(var i=0; i<timer.times.length; i++)
{
if(timer.times[i] == 0) { timer.callback(); break; }
document.getElementById("timer_"+i).innerHTML=timer.format(timer.times[i]);
timer.times[i]--;
}
},
start:function()
{
if(!timer.init)
{
timer.init=true;
setInterval(timer.ticker, 1000);
}
}
}
Is there a problem with the code?
Thank you for your help.

Just check your code for errors in opera mini console. Open your page in opera mini and write in address bar this:
server:console?post=http://path_to_your_page
Also, Opera Mini has javascript timers limits - it stops any timers after 2-5 seconds (depend from Opera Mini version). On my Android timer stops after 5 seconds(fiddle).

Timers work differently in operamini, Read https://dev.opera.com/articles/opera-mini-content-authoring-guidelines/
Copied from the above link,
Code registered with setTimeout() and setInterval() may be run before the page is sent, but it is unlikely that it will be called more than once because of script pausing

Related

iOS 9.3.2 Custom URL Scheme not launching app from Safari

My web page detects the OS and browser, and in the case of iOS Safari will launch my app using a custom URL scheme.
It works fine on my test devices, but I'm seeing an issue with a user using Safari/9.0 on iOS/9.3.2 - the link simply does nothing!
Are custom URL schemes no longer supported? Do I need to start using universal links instead?
For those interested, here is the Javascript code I use in iOS browsers (which is working 99% of the time):
var timer;
var heartbeat;
var lastInterval;
window.addEventListener("pageshow", function(evt){
clearTimers();
}, false);
window.addEventListener("pagehide", function(evt){
clearTimers();
}, false);
function getTime() {
return (new Date()).getTime();
}
// For all other browsers except Safari (which do not support pageshow and pagehide properly)
function intervalHeartbeat()
{
var now = getTime();
var diff = now - lastInterval - 200;
lastInterval = now;
if(diff > 1000)
{ // don't trigger on small stutters less than 1000ms
clearTimers();
}
}
function clearTimers()
{
clearTimeout(timer);
clearTimeout(heartbeat);
}
function intervalHeartbeat()
{
if (document.webkitHidden || document.hidden)
{
clearTimers();
}
}
function launch()
{
lastInterval = getTime();
heartbeat = setInterval(intervalHeartbeat, 200);
timer = setTimeout(function ()
{
logErrorToMyServer();
}, 2000);
//Launch app via custom URL scheme
window.location = "myapp://";
}
Custom URI schemes have been a not-good option since the introduction of iOS 9.2. Apple has definitely made it clear that Universal Links are the preferred approach to deep linking.
I'm not aware of any retroactive changes that would be causing Safari on 9.0 - 9.3.2 to do nothing in this situation (you should at least be getting an error pop-up), but this will continue to be unsupported for the foreseeable future and you should get Universal Links up and running as soon as possible. More details available in this blog post.

setInterval Breaks Page To Be Shown

I have that line of code:
var checkExist5 = setInterval(function() {
if (lock == 5 && $("#id1").length && $("#id2").length) {
console.log("debug");
clearInterval(checkExist5);
lock = -1;
}
}, 100);
it works at Firefox but it breaks the page at Internet Explorer. It does not give any error at console but the page is not shown (ie 9). What may be the reason?
I found the reason. It was because of
console.log("debug");
It was not working at Internet Explorer 9. There is an explanation here: Does IE9 support console.log, and is it a real function?

Opera and IE7 don't seem to be assigning value to variable

Yesterday I asked a question about running a script once a YouTube video is playing and after a lot of wrestling I figured this out.
Now the solution works in Firefox, Chrome, Safari, IE9 and IE8 but for some reason it's not working in Opera and IE7. I have very little Javascript experience so any help would be really appreciated.
I link the JS like this
<script type='text/javascript' src='http://www.example.ca/wp-includes/js/jquery/jquery.js?ver=1.7.1'></script>
<script type='text/javascript' src='http://www.example.ca/wp-content/plugins/slidedeck-lite-for-wordpress/lib/youtubeapi.js?ver=2011-04-28'></script>
<script type='text/javascript' src='http://www.example.ca/wp-content/plugins/slidedeck-lite-for-wordpress/lib/slidedeck.jquery.lite.js?ver=1.4.5'></script>
And within youtubeapi.js I run this
window.YTplayerState;
function onPlayerStateChange(evt) {
YTplayerState = evt.data;
}
window.YTplayerState; is an attempt to help fix the Opera/IE7 issue. Then within a pre-existing file for the SlideDeck plugin I run this
var YTplayerState;
var autoPlay = function() {
gotoNext = function() {
if (self.pauseAutoPlay === false) {
if (self.options.cycle === false && self.current == self.slides.length || YTplayerState == 1) {
self.pauseAutoPlay = true;
} else {
self.next();
}
if (YTplayerState == 1) {
self.pauseAutoPlay = true;
}
}
};
setInterval(gotoNext, self.options.autoPlayInterval);
};
Which most browser seem to be okay with, although that may just be luck, but it works. I know the issue in Opera is that YTplayerState never gets the value because if I manually change the value to one with a keypress function then it all behaves as expected.
If it's not anything with the code directly provided, are there any common quirks with Opera that I should look out for?
To my knowledge, this is a bug in Youtube video player. Sorry.
If you google for "onPlayerStateChange opera", you'll find more similar error reports.

Attaching callback to popup window in IE 9

I'm creating a popup window and attaching a callback function to it. There is a button in the popup's page which calls this callback when clicked. This works in Firefox 4 and Chrome 10, but not IE 9. The "myPopupCallback" property that I add to the window is found and executed by Firefox and Chrome. In IE, it is undefined.
Is there something about IE that causes problems with attaching data or functions to a window?
Main window code
var popup = window.open(url, '', 'status=0,menubar=0,toolbar=0,resizable=1,scrollbars=1');
$(popup.document).ready(function()
{
popup.myPopupCallback = function(rows)
{
// ...do stuff with rows...
};
});
Popup window code
$('#btn-ok').click(
function()
{
var rows = $('#rows');
// IE 9 throws an error on the next line because window.myPopupCallback is undefined
window.myPopupCallback(rows);
});
window.open() is a non-blocking operation which means that before the new window has finished opening JavaScript will move on to next line of code. Because of this, setting a property may not "stick" if it's done too soon. I just ran into this problem myself.
Thanks to a lot of help from Erik I found the following seems to work pretty well.
var popup = window.open(
url, '', 'status=0,menubar=0,toolbar=0,resizable=1,scrollbars=1'
);
$(popup.document).ready(function(){
var setPopupPropertiesInterval = setInterval(
function setPopupProperties() {
popup.myPopupCallback = function(rows)
{
// ...do stuff with rows...
};
if (popup.closed || popup.myPopupCallback) {
clearInterval(setPopupPropertiesInterval);
}
}, 1
);
});
This will keep trying to add the function to the popup window until it is added or the popup window is closed.
In my extremely brief testing this worked across browsers but I'm not sure about the performance implications of such a fast interval and had no issues with performance. Note that most (all?) browsers will not actually run the code in 1 ms intervals, but something a bit higher, usually 10 ms. Chrome is an exception to this in that it tries to get close to 1 or 2ms.
On one Windows XP machine running IE 7 I ran into an issue where the browser would freeze upon launching the pop-up. The window would pop-up but nothing would load and the browser would become slow to respond. However, I have tested this on several other machines running Windows XP and IE 7 and was not able to reproduce the issue.

Google Earth Browser Plugin not loading KML file in some browsers

code:
google.load("earth", "1");
function gemap_init()
{
google.earth.createInstance('gemap', initCB, failureCB);
}
function initCB(instance)
{
try {
ge = instance;
ge.getWindow().setVisibility(true);
console.log(ge.getPluginVersion());
google.earth.fetchKml(ge,
'http://example.com.au/maps/example.kml',
function (kmlObject) {
if (kmlObject) {
ge.getFeatures().appendChild(kmlObject);
}
if (kmlObject.getAbstractView() !== null) {
ge.getView().setAbstractView(kmlObject.getAbstractView());
}
}
);
} catch (e) {
console.log(e);
}
}
function failureCB(errorCode)
{
alert(errorCode);
}
google.setOnLoadCallback(gemap_init);
for some reason this is working in every browser on my PC - but when I test on random computers and browsers around the office it is failing to display the markers or move the camera from the kml.
operating systems and browsers range from XP to Vista, and using FF, Chrome, IE7, IE8 - there is no pattern to the failure.
failing plugins are the same version as working plugins.
this is becoming a hair-pulling event for me as i just can't see where the fail is.
EDIT:
just to make clear - it is working in all those browsers and all those OSs - but not always, and not consistently...
there is no change in the javascript or kml between it working and not working.
the kml is a valid document
all browsers report that they are using the same plugin version
The comment from Fraser has reminded that this question was left open...
We have resolved the problem by appending a unique ID which is regenerated whenever the KML data on the server is updated.
This seems to bust the GE cache and we no longer have any problems with missing or out of date data being loaded in the plugin.

Categories