in IE8 setInterval method not working - internet-explorer-8

When i tried the setInterval method in IE8 its not wokring
<body>
<script type="text/javascript">
function msg()
{
alert("hello world ");
document.writeln("hello world <br>");
}
//setInterval("msg();", 3000);
//setInterval(msg(), 3000);
//setInterval(msg, 3000);
setInterval(function(){msg()}, 3000);
</script>
</body>
when google i got several answers
window.setInterval jQuery function does not work on IE8
setinterval method not working
http://social.msdn.microsoft.com/Forums/nl-NL/netfxjscript/thread/ff7447f0-3c18-484b-a037-eaf9f60574a8
but when i tried those things on ie8 its not working

setInterval is working fine in your code. The problem is with what you're doing with it. Executing document.writeln is wiping out your document, which includes your JavaScript. To see this in action, just add <p>foo</p> somewhere in the body and you'll see that it disappears once document.writeln is executed. Remove the document.writeln line and you'll see that the alert occurs over and over again, as expected.
I believe the JavaScript will continue to run in WebKit browsers even though it's been wiped out, but not in non-WebKit browsers like Internet Explorer, Firefox, and Opera. Have a look at this question for some ideas on what to do.

Related

Modernizr detecting geolocation api not working

I'm trying to get simple code for modernizr js to say whether or not a browser can support geolocation api. Here's my code.
<script src="js/vendor/modernizr-2.8.3.min.js"></script>
<!-- check if geolocation works on browser -->
<script>
if(Modernizr.geolocation)
{
document.getElementById("geoConfirm").innerHTML = "This will work on this browser!";
}
else{
document.getElementById("geoConfirm").innerHTML = "This will not work on this browser";
}
</script>
<p id="geoConfirm">Test</p>
It's such simple code but it's not working, and it's bugging me because there's barely anything to go over. Thoughts?

Modernizr.videoautoplay object shows true, Modernizr.videoautoplay returning undefined

I'm using a custom Modernizr build, v3.3.0. I've created a simple JSFiddle example to illustrate: https://jsfiddle.net/cqkg7x45/6/.
console.log(Modernizr);
will show the Modernizr object, and when I inspect it in the JS console I can see "videoautoplay" is a property with a value of "true".
But, when I do
console.log(Modernizr.videoautoplay)
it returns "undefined".
I was originally seeing this issue in a WordPress theme I'm developing, but was also able to recreate in JSFiddle and a separate stand-alone HTML page. Also, Modernizr is putting the "videoautoplay" class on my HTML tag, even when I know the device does not support that feature (iPhone 5).
Update: This issue appears to be happening in Chrome (v47.0.2526.106), but not Firefox (v43.0.2).
I'm going to answer my own question in case anyone else runs into this problem. I found the solution on this SO post: How do I detect if the HTML5 autoplay attribute is supported?.
Since this is an "async" test you can't access the property using the syntax
Modernizr.videoautoplay
You have to use the .on() function, as shown in the above SO post:
Modernizr.on('videoautoplay', function(result){
if(result) {
alert('video autoplay is supported');
} else {
alert('video autplay is NOT supported');
}
});

Plain JS Ajax Upload Progress Event Not Working

I am trying to use object-oriented code to handle an AJAX upload. When I run the code, it sees the file, creates the XMLHttpRequest object, but I cannot seem to get the progress event to fire. The full source of my code can be found here: http://pastebin.com/89QawbS6
Here is a snippet:
var xhr = new XMLHttpRequest();
xhr.upload.addEventListener("progress", MyObj.trackProgress, false);
xhr.open("POST", url, true);
...
Then in that same object, different method:
trackProgress: function (event) {
console.log(event);
// stuff that should calculate percent
}
But that console.log(event) never fires.
Please note: I know jQuery is great, and there are a dozen awesome upload plugins that I could just use instead. I am not doing this for a class or homework, I just want to understand the process better myself. So offering a jQuery plugin as an answer is not what I'm looking for. I'm trying to make myself less dependent on jQuery.
This FF bug might be the reason for your issue. It's reported on MacOSX and another similar bug on Linux. I don't know if that matters but I tested on Windows. I still believe that your code is fine.

Desktop notifications allowing not working on chrome

So i want my web page to promt for validation on desktop notifications when it loads. So i added onload in body...
<body onload="setAllowNotification() return false;">
This works jsut fine on mozilla firefox but in Google chrome it doesn't show the question. But if i call that function like this, it works.
<a onclick="setAllowNotification(); return false;" href="#">Click to set allow notifications</a>
If it helps my setAllowNotification function:
function setAllowNotification()
{
window.webkitNotifications.requestPermission(permissionGranted);
}
So any ideas?
Try adding a semicolon to your onload event inline code:
Check this answer actually...
Webkit notifications requestPermission function doesn't work
You can only use it as part of a response to a user action - i.e. you cannot do it "onload"

Jw Player stops after a few seconds in Firefox

On chrome it works ok.
My flash version is WIN 10,0,32,18
Debug: No
This is the code that i wrote:
<script type="text/javascript" src="/swfobject.js"></script>
<div id="player">
Get the Flash Player
to see this player.
</div>
<script type="text/javascript">
var so = new SWFObject('player.swf', 'streambaby', '500', '15', '7');
so.addVariable('type', 'sound');
so.addVariable('file', 'http://path_to_shoutcast:port');
so.addVariable('displayheight', '15');
so.write('player');
</script>
The problem is that on chrome the stream works OK but on Firefox 3.5.2 it stopps after a few seconds.
I opened Firebug and hit the Net tab and I see that even after the playing stopps, firefox still downloads the stream.
I've searched on google and found answeres that said I should update my flash plugin, but it's the latest.
I managed to bypass this problem with adding
so.addVariable('duration','-1');
Before so.write, so the script becomes:
<script type="text/javascript">
var so = new SWFObject('player.swf', 'streambaby', '500', '15', '7');
so.addVariable('type', 'sound');
so.addVariable('file', 'http://path_to_shoutcast:port');
so.addVariable('displayheight', '15');
so.addVariable('duration','-1');
so.write('player');
</script>
Just for reference, I had a similar issue while streaming .nsv in Firefox with JW Player. It would only stream about a quarter of a second. I accidentally defined an invalid duration and it started to stream correctly. I ended up using this code:
so.addVariable('duration','invalid');
This works for me in Firefox, IE and Chrome.

Resources