how can I hide a part of javascript from IE - javascript

This is my javascript function to open a jquery dialog.
('#dialog').append(iframe).appendTo("body").dialog({
autoOpen: false,
modal: true,
resizable: false,
show: 'slide',
width: 800,
height: 700,
close: function() {
}
});
$('#dialog_click').click("callback",function() {
$('#dialog').dialog('open');
return false;
});
How can I hide the part show: 'slide, from IE ?

var options = {
autoOpen: false,
modal: true,
resizable: false,
width: 800,
height: 700,
close: function() {
}
};
if ( ! $.browser.msie){
options ['show'] = 'slide';
}
$('#dialog').append(iframe).appendTo("body").dialog(options);

try this
if ( ! $.browser.msie){
$( "#dialog" ).dialog( "option", "show", "slide" )
}

jquery has removed support for jQuery.browser.msie from version >= 1.9
so
var opts = {
autoOpen : false,
modal : true,
resizable : false,
show : 'slide',
width : 800,
height : 700,
close : function() {
}
};
if (!/msie/.test(window.navigator.userAgent)) {
opts.show = 'slide';
}
('#dialog').append(iframe).appendTo("body").dialog(opts);
$('#dialog_click').click("callback", function() {
$('#dialog').dialog('open');
return false;
});

$('#dialog').append(iframe).appendTo("body").dialog({
autoOpen: false,
modal: true,
resizable: false,
width: 800,
height: 700,
close: function() {
}
});
if(!$.browser.msie) {
$( "#dialog" ).dialog( "option", "show", "slide" );
}

There are several workarounds for this (conditional comments for the whole script, altering the property later, etc) but noone has posted a solution that does EXACTLY what you asked: excluding a portion of javascript only in IE.
Then take a look at this:
('#dialog').append(iframe).appendTo("body").dialog({
autoOpen: false,
modal: true,
resizable: false,
/*#cc_on #*/
/*#if (true)
#else #*/
show: 'slide',
/*#end #*/
width: 800,
height: 700,
close: function() {
}
});
$('#dialog_click').click("callback",function() {
$('#dialog').dialog('open');
return false;
});
IE won't include show: 'slide',, while non-IE browsers won't read the Conditional Compilation Statements , so the condition will fall in the (not-commented) else part.
Read more on Conditional Compilation Statements

There is several thing you can do.
First there are conditional comments , ie
<!--[if !IE ]>
<script>
$('#dialog').append(iframe).appendTo("body").dialog({
autoOpen: false,
modal: true,
resizable: false,
show: 'slide',
width: 800,
height: 700,
close: function() {
}
});
$('#dialog_click').click("callback",function() {
$('#dialog').dialog('open');
return false;
});
</script>
<![endif]-->
Or you can check jquery browser variable , as other guys are pointing.
Also if you are going this way, and you really want to target old version of IE you can use some functions specific to it ( like attachEvent )

Related

Textbox Losing value under Jquery Modal Dialog Box

I am using the script below for Modal Dialog box.I have a textbox and a button under dialog box div but when i click on button textbox value remains null why ? Can anyone help please
//Everything is working fine but textboxes are losing their values on button click
$("#dialog").dialog({ modal: true });
$("#dialog").dialog({ resizable: false });
$("#dialog").dialog({
buttons: {
//'Confirm': function () {
// $("[id*=btn_Confirm_View]").click();
//},
'Cancel': function () {
$(this).dialog('close');
}
}
});
$("#dialog").dialog({ draggable: false });
$("#dialog").dialog({ closeOnEscape: false });
$("#dialog").dialog({
width: 'auto',
autoOpen: false,
show: {
effect: "blind",
duration: 1500
},
hide: {
effect: "scale",
duration: 300
}
});
$("#dialog").dialog({
close: function (event, ui) {
}
});
//Everything is working fine but textboxes are losing their values on button
I got the solution ... :)
Here is my Modified Code...
// $("#dialog").dialog({ modal: true });
$("#dialog").dialog({ resizable: false });
$("#dialog").dialog({
buttons: {
//'Confirm': function () {
// $("[id*=btn_Confirm_View]").click();
//},
'Cancel': function () {
$(this).dialog('close');
}
}
});
$("#dialog").dialog({ draggable: false });
$("#dialog").dialog({ closeOnEscape: false });
$("#dialog").dialog({
width: 'auto',
autoOpen: false,
show: {
effect: "blind",
duration: 1500
},
hide: {
effect: "scale",
duration: 300
}
});
//I Added these two lines and now they are working fine
$("#dialog").parent().appendTo(jQuery("form:first"));
$("#dialog").dialog({
close: function (event, ui) {
}
});

Called javaScript function from jquery dialog button

I'm trying to call javascript function from jquery dialog buton, but it is not working
my code :
============================
$('#dialogAddActe').dialog({
autoOpen: false,
modal: true,
width: 800,
height:400,
show: "slide",
hide: "slide",
buttons: {
"Suivant": function() {
$(this).dialog("close");
if ($(this).checkNombre())
{
document.forms[0].dispatch.value = "ajouterActe";
document.forms[0].submit();
}
},
"Annuler": function() {
$(this).dialog("close");
document.forms[0].patientId.value="";
}
}
});
============================
$(this).checkNombre() is not working.
BR,
Med Baba
Remove $(this), just use if (checkNombre()).

Center Draggable Jquery Dialog

For the last few hours I've been trying to have an animated dialog that will initiate a puff animation, is draggable and when closed will center again when opened. As of now I have it so the animation initiates, it's draggable but when I close and open it, it's fixed in the same position it was dragged to.
I've tried using the open function, complete function in show/hide, setting the div/dialog in a function, using position: center and yeah...
Anyway, here is the code:
frm_location.jsp:
//this is in an "a" tag, can't seem to get it to display properly
id="NEW_LOCATION_BUTTON" href="javascript:openDialog('#dialog-form','#popupBoxCancel','orange-theme','625');" class="btn_sel">
jQueryDialog.js:
function openDialog(_dialog, _cancel, _theme, _size) {
jQuery(document).ready(function ($) {
$(_dialog).dialog({
autoOpen: true,
width: _size,
modal: true,
position: "center",
resizable: false,
draggable: true,
dialogClass: _theme,
show: {
effect: "puff",
percent: "-150",
duration: 250
},
hide: {
effect: "puff",
percent: "-150",
duration: 250,
},
});
$(_cancel).click(function() {
$(_dialog).dialog("close");
});
}
Take a look at this. I'm not sure how you're reopening the dialog, but this should do. jsfiddle code
<div id='dialog'>PUFF</div>
<button id='reopen'>OPEN DIALOG</button>
$(function () {
$('#reopen').click(function () {
$( "#dialog" ).dialog({ position: 'center'});
$('#dialog').dialog('open');
});
$('#dialog').dialog({
autoOpen: true,
width: 200,
modal: true,
position: "center",
resizable: false,
draggable: true,
show: {
effect: "puff",
percent: "-150",
duration: 250
},
hide: {
effect: "puff",
percent: "-150",
duration: 250,
},
});
});

JQuery Dialog - Replace Timeout with close button

I am using the code below and decided I want a close button instead of the timeout.
How can I replace the timeout with a close button with the code below?
<script type="text/javascript">
$(document).ready(function() {
$("#info_box").dialog({
autoOpen: false,
modal: true,
width: 400,
zIndex: 9999999,
resizable: false,
open: function() {
// close the dialog 10 secs after it's opened
setTimeout(function() {
$(this).dialog("close");
}, 10000);
}
});
$(".notavailable").bind("click", function() {
$("#info_box").dialog("open");
});
});
</script>
You just need to add a buttons property to the Object the dialog is created with, something like:
$("#info_box").dialog({
autoOpen: false,
modal: true,
width: 400,
zIndex: 9999999,
resizable: false,
buttons: [
{
text: "Close",
click: function () {
$(this).dialog("close");
}
}
]
});

Syntax Error? Jquery script not working in IE7

I am using the following code to open a modal box when a button is clicked. Works fine in all browsers but IE7 where I get an error.
This is the code. Have I done something wrong???
<script type="text/javascript">
$(document).ready(function(){
var dialogOpts = {
modal: true,
bgiframe: true,
autoOpen: false,
height: 550,
width: 550,
draggable: true,
resizeable: true,
title: "Invite a friend",
};
$("#invitebox").dialog(dialogOpts); //end dialog
$('#invitebutton').click(
function() {
$("#invitebox").load("widgets/invite_a_friend/index.php", [], function(){
$("#invitebox").dialog("open");
}
);
return false;
}
);
});
</script>
Remove the , at the end after title:
var dialogOpts = {
modal: true,
bgiframe: true,
autoOpen: false,
height: 550,
width: 550,
draggable: true,
resizeable: true,
title: "Invite a friend", // <-- REMOVE THIS COMMA
};
Also the .load() function takes an object and not array as second argument:
$("#invitebox").load("widgets/invite_a_friend/index.php", { }, function() {
$("#invitebox").dialog("open");
});
Here is the problem, the comma at the end:
title: "Invite a friend",
};
JSLint can tell you whether your code is correct.

Categories

Resources