Ok so the code below works on every browser except ios chrome and IE.
What changes can be made to make it compatible with those browsers
<script type="text/javascript">
!function(){
var campaign_link = "http://example.com/time&"; // REPLACE WITH YOUR LINK
var t;
try{
for(t=0;10>t;++t)history.pushState({},"","#");
onpopstate=function(t){t.state&&location.replace(campaign_link)}}
catch(o){}
}();
</script>
You are getting the error because of history API. Its not supported in sme browsers
All versions below Internet Explorer 9 definitely does not support history.pushState() or history.popState()
iOS has a fair few bug with the HTML5 History API.
You can try like :
window.addEventListener("popstate", function(e) {
window.location.href = location.href;
});
Related
The code below generates alert "Your browser is supported" even if the version is IE 10. It works perfectly with browsers such as IE 9, 8 and 7. I need to ensure only version IE 11 is allowed. Is there really anything wrong with the code?
<script type="text/javascript">
jQuery(document).ready(function($){
// true on IE11
// false on Edge and other IEs/browsers. filters.hide();
// Allow only IE 11 and other browsers like Chrome, Safar, firefox so on,
// but never allow lower versions of IE starting IE 10.
var div = document.createElement("div");
div.innerHTML = "<!--[if lt IE 11]><i></i><![endif]-->";
var isIeLessThan11 = (div.getElementsByTagName("i").length == 1);
if (isIeLessThan11) {
alert("Your web browser is out of date. Please complete this form using an approved browser, such as Edge, Chrome, Safari, or Firefox.");
} else {
alert("Your browser is supported");
}
});
</script>
According to wikipedia, conditional comments are not supported in IE10 and above. https://en.m.wikipedia.org/wiki/Conditional_comment
I've been trying to send a beacon on beforeunload and it seems to work on pretty much all modern browsers, except Chrome in incognito mode.
This is the code that works in all modern browsers, except Chrome in incognito mode:
window.onbeforeunload = function() {
navigator.sendBeacon("url");
}
Not even this code doesn't seem to work:
window.onbeforeunload = function() {
console.log('before unload')
}
Am I doing anything wrong or is it just Chrome's fault?
What's your setup (SO, Chrome version) ?
On Chrome 80.0.3987.116 / Ubuntu 64 and Chrome 79.0.3945.130 / Windows 10 the below snippet works falwlessy:
window.addEventListener('beforeunload', (event) => {
console.log("BEFORE")
navigator.sendBeacon("http://www.google.it");
// Cancel the event as stated by the standard.
event.preventDefault();
// Chrome requires returnValue to be set.
event.returnValue = '';
});
Screen of the request (incognito mode) sent on beforeunload:
Furthermore, notice:
To combat unwanted pop-ups, some browsers don't display prompts
created in beforeunload event handlers unless the page has been
interacted with. Moreover, some don't display them at all.
Ref: https://developer.mozilla.org/en-US/docs/Web/API/WindowEventHandlers/onbeforeunload
I have some JQuery and JavaScript code that works in Chrome and Firefox but not IE. The code is nested inside of SAS and I removed the SAS nesting. Does anyone see a reason why this code would error out in IE? related. I am using IE 11. I am getting the error: document.addEventListener( "DOMContentLoaded", completed, false );
<script type="text/JavaScript">
function saveMultiSelection(pageName) {
document.getElementById('save_degStudLevComma').value = $(""#degStudLev"").multipleSelect('getSelects');
document.getElementById('save_studyLevelComma').value = $(""#studyLevel"").multipleSelect('getSelects');
document.getElementById('save_sumLevComma').value = $(""#sumlev"").multipleSelect('getSelects');
document.getElementById('save_awardTypeComma').value = $(""#awardType"").multipleSelect('getSelects');
}
</script>
Why you don't use jquery all the way if you have it in your app already?
function saveMultiSelection(pageName) {
//(...)
$('#save_degStudLevComma').val($("#degStudLev").multipleSelect('getSelects'));
//(...)
}
You can see broswer support version -> https://developer.mozilla.org/en-US/docs/Web/Events/DOMContentLoaded
IE support = 9+ ->DOMContentLoaded
I'm using Soundmanager2 to play some audio files in a web site, but not using Flash.
It works fine with Firefox and Chrome, as they support ogg and mp3 respectively. However, it doesn't work with Opera 12.16. Theoretically, it supports ogg, and pass the condition if( supports_ogg_audio() ):
It is returning 1 in this function:
function supports_ogg_audio() {
var a = document.createElement('audio');
return !!(a.canPlayType && a.canPlayType('audio/ogg; codecs="vorbis"').replace(/no/, ''));
}
So it detects ogg support. But as I'm doing:
currentRow = thisPlayer.find(".total-row:first");
I get this error from the Opera console:
Unknown pseudo class
[id='total-playlist'] .total-row:first
So I'm guessing that this is the problem. How could select the first thisPlayer.find(".total-row") element with better browser compatibility?
It neither works in Safari5+ and IE9+
You need to use first-child selector instead of first. See information here.
JSON.stringify is not working in blackberry mobile it is working great in iphone and other browser. it is not prompting it in below example in blackberry mobile:
function sup() {
this.name;
}
var SUP = new sup();
SUP.name = 'XYZ' ;
var tt = JSON.stringify(SUP);
alert(tt);
You should create a fallback mechanism so browser uses the native JSON support if present, otherwise it download the library that #T.J. Crowder pointed out
Something like this should do the trick
<script>window.JSON||
document.write("<script src='js/my-json-library.js'>\x3C/script>")
</script>
It sounds like that version of the Blackberry browser doesn't support the new JSON object, which was introduced in ES5 (so, just recently). You can find several polyfills/shims, including ones from the "introducer" of JSON himself.