How to detect Acrobat X Pro installed on machine using javascript - javascript

How can I detect if Acrobat X Pro is installed on a machine using javascript. I have code that works for Adobe Reader. but now I have upgrdaed my adobe version to Acrobat X Pro. But it is not working for Acrobat X Pro using IE8.
var perform_acrobat_detection = function()
{
//
// The returned object
//
var browser_info = {
name: null,
acrobat : null,
acrobat_ver : null
};
if(navigator && (navigator.userAgent.toLowerCase()).indexOf("chrome") > -1)
browser_info.name = "chrome";
else if(navigator && (navigator.userAgent.toLowerCase()).indexOf("msie") > -1)
browser_info.name = "ie";
else if(navigator && (navigator.userAgent.toLowerCase()).indexOf("firefox") > -1)
browser_info.name = "firefox";
else if(navigator && (navigator.userAgent.toLowerCase()).indexOf("msie") > -1)
browser_info.name = "other";
try {
if(browser_info.name == "ie") {
var control = null;
//
// load the activeX control
//
try {
// AcroPDF.PDF is used by version 7 and later
control = new ActiveXObject('AcroPDF.PDF');
}
catch (e){}
if (!control) {
try {
// PDF.PdfCtrl is used by version 6 and earlier
control = new ActiveXObject('PDF.PdfCtrl');
}
catch (e) {}
}
if(!control) {
browser_info.acrobat == null;
return browser_info;
}
version = control.GetVersions().split(',');
version = version[0].split('=');
browser_info.acrobat = "installed";
browser_info.acrobat_ver = parseFloat(version[1]);
}
else if(browser_info.name == "chrome") {
for(key in navigator.plugins)
{
if(navigator.plugins[key].name == "Chrome PDF Viewer" || navigator.plugins[key].name == "Adobe Acrobat") {
browser_info.acrobat = "installed";
browser_info.acrobat_ver = parseInt(navigator.plugins[key].version) || "Chome PDF Viewer";
}
}
}
//
// NS3+, Opera3+, IE5+ Mac, Safari (support plugin array): check for Acrobat plugin in plugin array
//
else if(navigator.plugins != null)
{
var acrobat = navigator.plugins['Adobe Acrobat'];
if(acrobat == null)
{
browser_info.acrobat = null;
return browser_info;
}
browser_info.acrobat = "installed";
browser_info.acrobat_ver = parseInt(acrobat.version[0]);
}
}
catch(e)
{
browser_info.acrobat_ver = null;
}
return browser_info;
};
var browser_info = perform_acrobat_detection();

Related

Javascript is not working in IE

I am writing a javascript, that ll get the browser information and set them in cookies, so that I can use them in future.
The setCookies() is complext javascript function, that ll do some manipulation on the navoigator user agent and determine the browser.
This functions seems to work on all major browsers, but it is not working in IE (11, 10, 9, 8 , 7), I don't know why.
Other info : I am developing a Apache wicket application, version 1.4.19.
Here is the Javascript function
<script type="text/javascript">
function setCookies() {
var browser;
var version;
var click_ev = document.createEvent("MouseEvents");
click_ev.initEvent("click", true /* bubble */, true /* cancelable */);
document.cookie = "user_agent=" + navigator.userAgent + "; path=/";
document.cookie = "navigator_app_platform=" + navigator.platform
+ "; path=/";
var platform = navigator.platform;
if (platform == "iPad" || platform == "iPhone" || platform == "iPod"
|| platform == "iPod touch") { // For iPhones iPads and iPods
var userAgent = navigator.userAgent;
var chromeIndex = userAgent.indexOf("criOS");
var opera = userAgent.indexOf("OPiOS");
var ucIndex = userAgent.indexOf("UCBrowser");
var coast = userAgent.indexOf("Coast");
var mercury = userAgent.indexOf("Mercury");
var safari = userAgent.indexOf("Safari");
var webkit = userAgent.indexOf("AppleWebKit");
// Chrome detection
if(chromeIndex > 0) {
browser = "chrome";
var arr = userAgent.split("criOS/");
arr = arr[1].split(".");
version = arr[0];
}
// Safari detection
else if(opera < 0 && ucIndex < 0 && coast < 0 && mercury < 0 && safari > 0 && webkit > 0) {
browser = "safari";
var arr = userAgent.split("AppleWebKit/");
arr = arr[1].split(".");
version = arr[0];
} else {
browser = "unknown";
version = -1;
}
} else if(platform == "Win32" || platform == "MacIntel") { // For windows and mac
// Browser detection
var isOpera = !!window.opera || navigator.userAgent.indexOf(' OPR/') >= 0;
// Opera 8.0+ (UA detection to detect Blink/v8-powered Opera)
var isFirefox = typeof InstallTrigger !== 'undefined'; // Firefox 1.0+
var isSafari = Object.prototype.toString.call(window.HTMLElement).indexOf('Constructor') > 0;
// At least Safari 3+: "[object HTMLElementConstructor]"
var isChrome = !!window.chrome && !isOpera; // Chrome 1+
var isIE = /*#cc_on!#*/false || !!document.documentMode; // At least IE6
if (isOpera) {
browser = "opera";
} else if (isFirefox) {
browser = "firefox";
} else if (isChrome) {
browser = "chrome";
} else if (isIE) {
browser = "ie";
} else if (isSafari) {
browser = "safari";
} else {
browser = "unknown";
}
if (browser == "firefox") {
var arr = navigator.userAgent.split("Firefox/");
arr = arr[1].split(".");
version = arr[0];
} else if (browser == "chrome") {
var arr = navigator.userAgent.split("Chrome/");
arr = arr[1].split(".");
version = arr[0];
} else if (browser == "ie") {
var arr = navigator.userAgent.split("MSIE ");
arr = arr[1].split(".");
version = arr[0];
} else if (browser == "safari") {
var arr = navigator.userAgent.split("AppleWebKit/");
arr = arr[1].split(" ");
arr = arr[0].split(".");
version = arr[0];
} else if (browser == "opera") {
var arr = navigator.userAgent.split("OPR/");
arr = arr[1].split(".");
version = arr[0];
} else if (browser == "unknown") {
version = -1;
}
} else if(platform == "Android" || platform == "Linux armv7l") { // For android
var userAgent = navigator.userAgent;
var chromeIndex = userAgent.indexOf("Chrome");
var opera = userAgent.indexOf("OPR");
var ucIndex = userAgent.indexOf("UCBrowser");
var coast = userAgent.indexOf("Coast");
var firefox = userAgent.indexOf("Firefox");
// Chrome detection
if(chromeIndex > 0 && opera < 0 && ucIndex < 0 && coast < 0) {
browser = "chrome";
var arr = userAgent.split("Chrome/");
arr = arr[1].split(".");
version = arr[0];
} else if(firefox > 0) { // Firefox detection
browser = "firefox";
var arr = userAgent.split("Firefox/");
arr = arr[1].split(".");
version = arr[0];
} else if(opera > 0) { // Opera detection
browser = "opera";
var arr = userAgent.split("OPR/");
arr = arr[1].split(".");
version = arr[0];
} else { // Unknown browser
browser = "unknown";
version = -1;
}
} else { // For other platforms
version = -1;
browser = "other_platform";
}
document.cookie = "browser_version=" + version + "; path=/";
document.cookie = "browser_name=" + browser + "; path=/";
document.getElementById("redirect").dispatchEvent(click_ev);
}
</script>
I did fix the issue after some playing around.
It turned out that, in the newer versions of IE userAgent is not same in every versions.
The user agent in my IE10 does not contain "MSIE", and I was trying to split the userAgent by "MSIE", and it was resulting a null pointer situation.
So the IE version detection script changed from :
if (browser == "ie") {
var arr = navigator.userAgent.split("MSIE ");
arr = arr[1].split(".");
version = arr[0];
}
To :
if (browser == "ie") {
var v1 = navigator.userAgent.indexOf("MISE");
var v2 = navigator.userAgent.indexOf("rv:");
if(v1 > 0) {
var arr = navigator.userAgent.split("MSIE ");
arr = arr[1].split(".");
version = arr[0];
} else if(v2 > 0) {
var arr = navigator.userAgent.split("rv:");
arr = arr[1].split(".");
version = arr[0];
}
Thanks :)

How to replace cross browser javascript to jQuery

Here is my code I have written - javascript code for IE and Chrome.
How can replace this with jQuery?
All this code working fine with the Javascript but I want replace it with jQuery.
Please help me to resolve this issue
function GetObject(objName)
{
var objReturn;
if (navigator.appName == 'Microsoft Internet Explorer')
{
var x = top.document.forms.Form1.ownerDocument.getElementById("iframe_module_details");
var y = (x.contentWindow || x.contentDocument);
if (y.document && y.document.getElementById(objName))
return y.document.getElementById(objName)
if (window.Form1 && window.Form1.document.getElementById(objName)) {
objReturn = window.Form1.document.getElementById(objName);
}
else if (window.parent.document.forms[0].document.getElementById(objName))
{
objReturn = window.parent.document.forms[0].document.getElementById(objName);
}
else if (top.frames[0].document.forms[0].document.getElementById(objName))
{
objReturn = top.frames[0].document.forms[0].document.getElementById(objName);
}
else if (window.parent && window.parent.Form1 && window.parent.Form1.document.getElementById(objName)) {
objReturn = window.parent.Form1.document.getElementById(objName);
}
else if (opener) {
if (opener.opener) {
if (opener.opener.parent.Form1 && opener.opener.parent.Form1.document.getElementById(objName)) {
objReturn = opener.opener.parent.Form1.document.getElementById(objName);
}
}
else if (opener.parent && opener.parent.Form1 && opener.parent.Form1.document.getElementById(objName)) {
objReturn = opener.parent.Form1.document.getElementById(objName);
}
}
}
else { //For Chrome
if (window.Form1 && window.Form1.document.getElementById(objName)) {
objReturn = window.Form1.document.getElementById(objName);
}
else if (document.getElementById(objName))
{
objReturn = window.parent.document.forms[0].document.getElementById(objName);
}
else if (document.getElementById(objName))
{
objReturn = top.frames[0].document.forms[0].document.getElementById(objName);
}
else if (window.parent && window.parent.Form1 && window.parent.Form1.document.getElementById(objName)) {
objReturn = window.parent.Form1.document.getElementById(objName);
}
else if (opener) {
if (opener.opener) {
if (opener.opener.parent.Form1 && opener.opener.parent.Form1.document.getElementById(objName)) {
objReturn = opener.opener.parent.Form1.document.getElementById(objName);
}
}
else if (opener.parent && opener.parent.Form1 && opener.parent.Form1.document.getElementById(objName)) {
objReturn = opener.parent.Form1.document.getElementById(objName);
}
}
}
//alert(objReturn);
return objReturn;
}
I don't want multiple code for different browser
Your code is very big for this simple task.
If I read correctly your code, it seems to always use getElementById, so it's very easy with jQuery.
So you can replace all this code with this function :
function GetObject(objName) {
return $('#'+objName).get(0); // Return the DOM element of objName, same as document.getElementById(objName)
}

How to remove end space when firefox double click selected text

Firefox double click selected text with next space. How to remove end space on screen with javascript.
Thank you so much.
Here's solution that does remove trailing whitespace character selected on doubleclick in Windows browsers, somewhat emulating Firefox about:config setting layout.word_select.eat_space_to_next_word being set to "false".
Does it "On screen, not in variable".
Tested in Chrome 60.0.3112.113, Firefox 55.0.3, IE8 and IE Edge(14).
It's still sometimes visible as selection shrinks from that extra space but nothing can be done about that.
Works for both arbitrary text and input/textareas(those need completely different approaches).
Uses jQuery
(function() {
var lastSelEvent = null;
var lastSelInputEvent = null;
var lastDblClickEvent = null;
var selchangeModTs = null;
$(document).on('selectstart selectionchange', function (e) //not input/textarea case
{
fixEventTS(e);
lastSelEvent = e;
if (( selchangeModTs != null) && (new Date().getTime() - selchangeModTs < 50)) //without this we get infinite loop in IE11+ as changing selection programmatically apparently generates event itself...
return;
handleSelEvent(e);
});
$(document).on('select', function (e) //input/textarea
{
fixEventTS(e);
lastSelInputEvent = e;
handleSelEvent(e);
});
$(document).on('dblclick',function(e)
{
fixEventTS(e);
lastDblClickEvent = e;
handleSelEvent(e);
});
function fixEventTS(e)
{
if (typeof e.timeStamp == 'undefined') //IE 8 no timestamps for events...
{
e.timeStamp = new Date().getTime();
}
}
function handleSelEvent(e)
{
if (lastDblClickEvent===null)
return;
if ( ((e.type==='selectstart') || (e.type==='selectionchange') || (e.type==='dblclick')) && (lastSelEvent != null) && (Math.abs(lastDblClickEvent.timeStamp - lastSelEvent.timeStamp) < 1000) ) // different browsers have different event order so take abs to be safe...
{
switch (lastSelEvent.type)
{
case 'selectstart':
setTimeout(handleSelChange,50); //IE8 etc fix, selectionchange is actually only change, not selection "creation"
break;
case 'selectionchange':
handleSelChange();
break;
}
}
if ( ((e.type==='select') || (e.type==='dblclick')) && (lastSelInputEvent != null) && (Math.abs(lastDblClickEvent.timeStamp - lastSelInputEvent.timeStamp) < 1000) ){
handleSel(lastSelInputEvent);
}
}
function handleSel(e)
{
//right whitespace
while (/\s$/.test(e.target.value.substr(e.target.selectionEnd - 1, 1)) && e.target.selectionEnd > 0) {
e.target.selectionEnd -= 1;
}
//left whitespace
while (/\s$/.test(e.target.value.substr(e.target.selectionStart, 1)) && e.target.selectionStart > 0) {
e.target.selectionStart += 1;
}
}
function handleSelChange() {
var sel = null;
if (typeof window.getSelection == 'function') // modern browsers
sel = window.getSelection();
else if (typeof document.getSelection == 'function')
sel = document.getSelection();
if (sel && !sel.isCollapsed) {
var range = sel.getRangeAt(0); //have to use range instead of more direct selection.expand/selection.modify as otherwise have to consider selection's direction in non-doubleclick cases
if (range.endOffset > 0 && (range.endContainer.nodeType===3) && (range.endContainer.textContent != ''/*otherwise rightside pictures get deleted*/))
{
//right whitespaces
while ( /[\s\S]+\s$/.test(range.endContainer.textContent.substr(0,range.endOffset)) ) { //have to use instead of range.toString() for IE11+ as it auto-trims whitespaces there and in selection.toString()
selchangeModTs = new Date().getTime();
range.setEnd(range.endContainer, range.endOffset - 1);
}
}
if ((range.startContainer.nodeType===3) && (range.startContainer.textContent != '') && (range.startOffset < range.startContainer.textContent.length)) {
//left whitespaces
while (/^\s[\s\S]+/.test(range.startContainer.textContent.substr(range.startOffset))) {
selchangeModTs = new Date().getTime();
range.setStart(range.startContainer, range.startOffset + 1);
}
}
selchangeModTs = new Date().getTime();
sel.removeAllRanges(); //IE11+ fix, in Firefox/Chrome changes to range apply to selection automatically
sel.addRange(range);
}
else if (typeof document.selection != 'undefined') //IE 10 and lower case
{
var range = document.selection.createRange();
if (range && range.text && range.text.toString()) {
while ((range.text != '') && /[\s\S]+\s$/.test(range.text.toString())) {
selchangeModTs = new Date().getTime();
range.moveEnd('character', -1);
range.select();
}
while ((range.text != '') && /^\s[\s\S]+/.test(range.text.toString())) {
selchangeModTs = new Date().getTime();
range.moveStart('character', 1);
range.select();
}
}
}
}
})();
If you don't need old IE support & limitint to doubleclick-only removal it can be greatly simplified and only needs to handle selectchange and select events to respective functions.(but then you actually can't select stuff with keyboard)
Edit:
Using Rangy lib(https://github.com/timdown/rangy) Core + TextRange for non-input elements selection trimming is way better than my basic attempt that only works if endContainer happens to be a text node. Basic action of selection trimming is
rangy.getSelection().trim()
Minimal includes are
https://cdnjs.cloudflare.com/ajax/libs/jquery/3.2.1/jquery.min.js
https://cdnjs.cloudflare.com/ajax/libs/rangy/1.3.0/rangy-core.min.js
https://cdnjs.cloudflare.com/ajax/libs/rangy/1.3.0/rangy-textrange.min.js
Rangy implementation additionally supporting triple-click whole-line selection trimming
(function() {
var lastSelEvent = null;
var lastSelInputEvent = null;
var lastDblClickEvent = null;
var selchangeModTs = null;
var tripleclickFixBound = false;
var selStartTimout = null;
$(document).on('selectstart selectionchange', function (e) //non-inputs
{
fixEventTS(e);
lastSelEvent = e;
if ( ( selchangeModTs != null) && (new Date().getTime() - selchangeModTs < 50) ) //ie11+ fix otherwise get self-loop with our selection changes generating this event
return;
handleSelEvent(e);
});
if ('onselect' in document.documentElement) {
$(document).on('select', function (e) //input/textarea
{
fixEventTS(e);
lastSelInputEvent = e;
handleSelEvent(e);
});
}
$(document).on('click',function(e){
if (typeof e.originalEvent.detail !== 'undefined')
{
multiclickHandlerfunction(e);
}
else
{
fixEventTS(e);
if (!tripleclickFixBound) {
$(document).on('dblclick', function (e) {
fixEventTS(e);
selchangeModTs = null;
lastDblClickEvent = e;
handleSelEvent(e);
});
tripleclickFixBound=true;
}
if ( (lastDblClickEvent != null) && (e.timeStamp - lastDblClickEvent.timeStamp < 300))
{
lastDblClickEvent = e;
selchangeModTs = null;
handleSelEvent(e);
}
}
});
function multiclickHandlerfunction(e) {
if (e.originalEvent.detail === 2 || e.originalEvent.detail === 3) {
fixEventTS(e);
selchangeModTs = null;
lastDblClickEvent = e;
handleSelEvent(e);
}
}
function fixEventTS(e)
{
if (typeof e.timeStamp == 'undefined') //IE 8
{
e.timeStamp = new Date().getTime();
}
}
function handleSelEvent(e)
{
if (lastDblClickEvent===null)
return;
if ( ((e.type==='selectstart') || (e.type==='selectionchange') || (e.type==='dblclick') || (e.type==='click')) && (lastSelEvent != null) && (Math.abs(lastDblClickEvent.timeStamp - lastSelEvent.timeStamp) < 1000) ) // different order of events in different browsers...
{
switch (lastSelEvent.type)
{
case 'selectstart':
case 'selectionchange':
clearTimeout(selStartTimout);
selStartTimout = setTimeout(handleSelChange,(/msie\s|trident\/|edge\//i.test(window.navigator.userAgent)?150:0));
break;
}
}
if ( ((e.type==='select') || (e.type==='dblclick') || (e.type==='click')) && (lastSelInputEvent != null) && (Math.abs(lastDblClickEvent.timeStamp - lastSelInputEvent.timeStamp) < 1000) )
{
handleSel(lastSelInputEvent);
}
}
function handleSel(e)
{
if (typeof(e.target.selectionEnd) != 'undefined') {
//left whitespace
while (/\s$/.test(e.target.value.substr(e.target.selectionEnd - 1, 1)) && e.target.selectionEnd > 0) {
e.target.selectionEnd -= 1;
}
//right whitespace
while (/^s/.test(e.target.value.substr(e.target.selectionStart - 1, 1)) && e.target.selectionStart > 0) {
e.target.selectionStart += 1;
}
}
}
function handleSelChange() {
var sel = rangy.getSelection();
if (sel && !sel.isCollapsed) {
selchangeModTs = new Date().getTime();
sel.trim();
}
else if (typeof document.selection != 'undefined') //IE 10- input/textArea case
{
var range = document.selection.createRange();
if (range && range.text && range.text.toString()) {
while ((range.text != '') && /[\s\S]+\s$/.test(range.text.toString())) {
selchangeModTs = new Date().getTime();
range.moveEnd('character', -1);
range.select();
}
while ((range.text != '') && /^\s[\s\S]+/.test(range.text.toString())) {
selchangeModTs = new Date().getTime();
range.moveStart('character', 1);
range.select();
}
}
}
}
})($,window);
CodePen demo
One thing I tried was to use range.setEnd() using the selection focus and anchor node and offset but -1.
Please excuse the lack of checks for browser compatibility.
var selection = window.getSelection();
var range = selection.getRangeAt(0);
var selected = range.toString();
if (!selection.isCollapsed) {
if (/\s+$/.test(selected)) {
if (selection.focusOffset > selection.anchorOffset) {
range.setEnd(selection.focusNode, selection.focusOffset - 1);
} else {
range.setEnd(selection.anchorNode, selection.anchorOffset - 1);
}
}
}
I am unsure if it works in IE/Edge but Chrome seems happy with it.
You must be using a Windows machine. And so you are seeing this issue. It doesnt exists on ubuntu machine.
Also if you need to remove the trailing space with Js
Try something like this.
document.ondblclick = function () {
var sel = (document.selection && document.selection.createRange().text) ||
(window.getSelection && window.getSelection().toString());
var selection = window.getSelection();
$('#new_word').text(sel.trim());
};
Check this jsFiddle http://jsfiddle.net/shinde87sagar/FvkwV/
Thanks to #James Bellaby
It worked for me using Chrome 83, this is the code for removing leading and trailing spaces from the selected range.
function fix_selection(range) {
var selection = window.getSelection();
var selected = range.toString();
range = selection.getRangeAt(0);
let start = selection.anchorOffset;
let end = selection.focusOffset;
if (!selection.isCollapsed) {
if (/\s+$/.test(selected)) { // Removes leading spaces
if (start > end) {
range.setEnd(selection.focusNode, --start);
} else {
range.setEnd(selection.anchorNode, --end);
}
}
if (/^\s+/.test(selected)) { // Removes trailing spaces
if (start > end) {
range.setStart(selection.anchorNode, ++end);
} else {
range.setStart(selection.focusNode, ++start);
}
}
}
return range
}
just put the text inside a label and the problem will be solved
Javascript has a trim() method which trims tailing (end) and leading spaces.
e.g.
var str = " Hello World! ";
str = str.trim(); // returns "Hello World"
Ref: http://www.w3schools.com/jsref/jsref_trim_string.asp

Custom checkbox not working in Chrome and Safari browser

i used below code for custom checkbox,
HTML
<div class="agree">
<label for="agree_check" class="label_check"><input type="checkbox" class="agree_check" id="agree_check" />Agree</label>
</div>
CSS
.has-js .label_check { padding-left: 34px; }
.has-js .label_check { background: url(../images/box1.png) no-repeat; }
.has-js label.c_on { background: url(../images/box1-with-mark.png) no-repeat; }
.has-js .label_check input { position: absolute; left: -9999px; }
Script
<script type="text/javascript">
var d = document;
var safari = (navigator.userAgent.toLowerCase().indexOf('safari') != -1) ? true : false;
var gebtn = function(parEl,child) { return parEl.getElementsByTagName(child); };
onload = function() {
var body = gebtn(d,'body')[0];
body.className = body.className && body.className != '' ? body.className + ' has-js' : 'has-js';
if (!d.getElementById || !d.createTextNode) return;
var ls = gebtn(d,'label');
for (var i = 0; i < ls.length; i++) {
var l = ls[i];
if (l.className.indexOf('label_') == -1) continue;
var inp = gebtn(l,'input')[0];
if (l.className == 'label_check') {
l.className = (safari && inp.checked == true || inp.checked) ? 'label_check c_on' : 'label_check c_off';
l.onclick = check_it;
};
if (l.className == 'label_radio') {
l.className = (safari && inp.checked == true || inp.checked) ? 'label_radio r_on' : 'label_radio r_off';
l.onclick = turn_radio;
};
};
};
var check_it = function() {
var inp = gebtn(this,'input')[0];
if (this.className == 'label_check c_off' || (!safari && inp.checked)) {
this.className = 'label_check c_on';
if (safari) inp.click();
} else {
this.className = 'label_check c_off';
if (safari) inp.click();
};
};
var turn_radio = function() {
var inp = gebtn(this,'input')[0];
if (this.className == 'label_radio r_off' || inp.checked) {
var ls = gebtn(this.parentNode,'label');
for (var i = 0; i < ls.length; i++) {
var l = ls[i];
if (l.className.indexOf('label_radio') == -1) continue;
l.className = 'label_radio r_off';
};
this.className = 'label_radio r_on';
if (safari) inp.click();
} else {
this.className = 'label_radio r_off';
if (safari) inp.click();
};
};
</script>
now i need to check the checkbox is checked or not.. it is works in FF but not works in Chrome and Safari browser.
if (jQuery('#agree_check').is(':checked')) {
alert("checked");
}
else
{
alert("Not checked");
}
when i checked the checkbox it displays "checked" in FF.. but in Chrome and safari it displays "not checked".
what is the issue?
My solution, working also on server side - codebehind (runat="server" attribute for label and checkbox), consist to add checked/unchecked state for critical browser. Maybe this work for all browser, clearing if statement.
var check_it = function () {
var inp = gebtn(this, 'input')[0];
if (this.className == 'label_check c_off' || (!safari && inp.checked)) {
this.className = 'label_check c_on';
if (chrome) inp.checked = true;
if (safari) inp.click();
} else {
this.className = 'label_check c_off';
if (chrome) inp.checked = false;
if (safari) inp.click();
};
};
Finally i found answer for this, it is just check in another way to make that condition true,
if (jQuery('#agree_check').is(':checked') || (jQuery('div.agree label').hasClass('c_on'))) {
alert("checked");
}
else
{
alert("Not checked");
}
now it's works fine in all browsers.
Thanks,
Ravichandran

How to show full screen popup with JavaScript?

I would like to show full screen popup with JavaScript? I use this code below but it isn't works on Firefox and Opera browser.
function detectVersion()
{
version = parseInt(navigator.appVersion);
return version;
}
function detectOS()
{
if (navigator.userAgent.indexOf('Win') == -1) {
OS = 'Macintosh';
} else {
OS = 'Windows';
}
return OS;
}
function detectBrowser()
{
if (navigator.appName.indexOf('Netscape') == -1) {
browser = 'IE';
} else {
browser = 'Netscape';
}
return browser;
}
function FullScreen(url){
var adjWidth;
var adjHeight;
if ((detectOS() == 'Macintosh') && (detectBrowser() == 'Netscape')) {
adjWidth = 20;
adjHeight = 35;
}
if ((detectOS() == 'Macintosh') && (detectBrowser() == 'IE')) {
adjWidth = 20;
adjHeight = 35;
winOptions = 'fullscreen=yes';
}
if ((detectOS() == 'Windows') && (detectBrowser() == 'Netscape')) {
adjWidth = 30;
adjHeight = 30;
}
if (detectVersion() < 4) {
self.location.href = url;
} else {
var winWidth = screen.availWidth - adjWidth;
var winHeight = screen.availHeight - adjHeight;
var winSize = 'width=' + winWidth + ',height=' + winHeight;
var thewindow = window.open(url, 'WindowName', winSize);
thewindow.moveTo(0,0);
}
}
function MakeItSo(url){
if ((detectOS() == 'Windows') && (detectBrowser() == 'IE')) {
window.open(url,'windowname','fullscreen=yes');
} else {
onload=FullScreen();
}
}
I would appreciate help,
Nguyen
1) most modern browsers block popups, so your work will just be disabled.
2) opening a full screen popup blatantly invades the users environment. If it's an application that you want to run full screen, it would be better to include a note to educate your users about the F11 key (on windows Fx, IE)
Have you checked the HTML5 fullscreen API?
document.body.requestFullscreen();
(Don't forget the vendor prefixs!)
If the browser don't support it you can try to use fullscreen popups as you do or just prompt your user to enter fullscreen mode themselves.

Categories

Resources