I am having a problem with closing a pop window. My problem is unique in kind if I click Logout from the parent, it closes all the windows, but when I log out from a child, then I am logging out from Parent, so it does not close the other child windows that are open.
When I am logging out from a child and then I am logging out from a parent, I checked in console and it is not going inside the if block.
The only variation between when I am logging out from a child and parent window is if I logout from parent it will close all the window and redirect parent and if I logout from child first it will create modal dialog box on parent with message session time out.
When I am logging out from child I am getting an Invalid Session Id passed from server and then I am invoking function
showModalBoxForInvalidSessionInfo
In this when I am checking in console I am not get the awin and bwin variable value. They are setting to undefined. But if I call onLogout function directly it will get the actual value.
I am not able to understand what is the difference here why the value is not getting inside even when I am declaring it as a gloabal variable.
I am pasting my JS file for the refrence
var userName;
var sessionId;
var userName;
var userId;
var awin;
var bwin;
$(document).ready(
function() {
userName = getURLParameters('userName');
sessionID = getURLParameters('requestID');
userId = getURLParameters('userId');
var welcomeMsg = document.getElementById('welcomeMsg');
var text = document.createTextNode('Welcome ' + userName );
var img = document.createElement('img');
img.style.height = '16px';
img.style.width = '16px';
img.src = 'images/arrow.png';
welcomeMsg.appendChild(text);
welcomeMsg.appendChild(img);
//style="width:16px; height:16px;"
console.log("Ready");
var fullAuthUrl = authorizationUrl
+ "?requestType=getRoles&username=" + userId
+ "&requestID=" + sessionID;
console.log(fullAuthUrl);
jQuery.support.cors = true;
$.ajaxSetup({
cache : false
});
$.ajax({
url : fullAuthUrl,
dataType : 'text',
crossOrigin : true,
cache : false,
type : 'GET',
success : function(response) {
//console.log("Success");
var responseBodyFull = response.replace(/^\s+|\s+$/g, '');
//responseBodyFull = response;
if (responseBodyFull == "Invalid Session Id passed") {
console.log("Invalid Session");
showModalBoxForInvalidSessionInfo();
}
console.log(responseBodyFull);
enableOrDisableLinks(responseBodyFull);
}
});
});
function b() {
sessionId = getURLParameters('requestID');
userName = getURLParameters('userName');
userId = getURLParameters('userId');
lvalue = getURLParameters('lValue');
lver = getURLParameters('lVer');
window.name = "parent";
var intWidth = screen.width - 10; //Adjust for the end of screen
var intHeight = screen.height - 80; //Adjust for the Icon Bar at the bottom of the window.
var strWinProp = " toolbar=no" //Back, Forward, etc...
+ ",location=no" //URL field
+ ",directories=no" //"What's New", etc...
+ ",status=yes" //Status Bar at bottom of window.
+ ",menubar=no" //Menubar at top of window.
+ ",resizable=yes" //Allow resizing by dragging.
+ ",scrollbars=yes" //Displays scrollbars is document is larger than window.
+ ",titlebar=yes" //Enable/Disable titlebar resize capability.
+ ",width="+intWidth //Standard 640,800/788, 800/788
+ ",height="+intHeight //Standard 480,600/541, 600/566
+ ",top=0" //Offset of windows top edge from screen.
+ ",left=0" //Offset of windows left edge from screen.
+ "";
bwin = window.open(bUrl + userName + "&requestID=" + sessionId
+ "&userId=" + userId,'_blank',strWinProp);
}
function a() {
sessionId = getURLParameters('requestID');
userName = getURLParameters('userName');
userId = getURLParameters('userId');
lvalue = getURLParameters('lValue');
lver = getURLParameters('lVer');
window.name = "parent";
var intWidth = screen.width - 10; //Adjust for the end of screen
var intHeight = screen.height - 80; //Adjust for the Icon Bar at the bottom of the window.
var strWinProp = " toolbar=no" //Back, Forward, etc...
+ ",location=no" //URL field
+ ",directories=no" //"What's New", etc...
+ ",status=yes" //Status Bar at bottom of window.
+ ",menubar=no" //Menubar at top of window.
+ ",resizable=yes" //Allow resizing by dragging.
+ ",scrollbars=yes" //Displays scrollbars is document is larger than window.
+ ",titlebar=yes" //Enable/Disable titlebar resize capability.
+ ",width="+intWidth //Standard 640,800/788, 800/788
+ ",height="+intHeight //Standard 480,600/541, 600/566
+ ",top=0" //Offset of windows top edge from screen.
+ ",left=0" //Offset of windows left edge from screen.
+ "";
awin = window.open(aUrl + userName + "&requestID=" + sessionId + "&userId="
+ userId,'_blank',strWinProp);
}
function showModalBoxForInvalidSessionInfo(){
$("#modelView").dialog({
autoOpen : false,
modal : true,
buttons : [ {
text : "OK",
icons : {
primary : "ui-icon-heart"
},
click : function() {
$(this).dialog("close");
}
}]
});
$("#modelView" ).dialog("open");
$("#modelView").text("Session Timed Out");
}
function getXmlHttpRequestObject() {
if (window.XMLHttpRequest) {
return new XMLHttpRequest(); //To support the browsers IE7+, Firefox, Chrome, Opera, Safari
} else if(window.ActiveXObject) {
return new ActiveXObject("Microsoft.XMLHTTP"); // For the browsers IE6, IE5
} else {
alert("Error due to old verion of browser upgrade your browser");
}
}
function onLogout(){
if (awin && !awin.closed) {
awin.close();
}
if (bwin && !bwin.closed) {
bwin.close();
}
window.location = loginPageUrl;
}
HTML file is very simple having two buttons calling function a and function b and a menu from where function onLogout is called.
Somebody please help me on this.
Related
I'm having a problem where my cookies are not being read by Safari or MS Edge. It works fine in all the other browsers just not in these 2.
Has anyone come across a similar issue? If so how did you manage to sort it out? Thank you.
$('.primary-button.eligibility-button').mousedown(function() {
var selectedCard = $('input[name="cardInterestOption"]:checked').next().text();
var balanceTransferOption = $('input[name="balanceTransferOption"]:checked').next().text().replace(/[a-z]/g,'');
var annualIncome = parseFloat($( "input[name='annualIncome']").val());
var otherIncome = parseFloat($( "input[name='otherIncome']").val());
var totalIncome = annualIncome + otherIncome;
document.cookie = "creditCardSelectorEligibility=" + selectedCard + "; path=/;";
document.cookie = "creditCardBalanceTransfer=" + balanceTransferOption + "; path=/;";
document.cookie = "creditCardTotalIncome=" + totalIncome + "; path=/;";
});
(function() {
var page = "";
var percentage = "NA";
var path = location.pathname;
if(/results/.test(path)){
page = "Success";
var results = "";
var percent = $(".results-banner:eq(0)").text();
if(/\b[0-9]{2}/.test(percent)){
results = percent.match(/\b[0-9]{2}/)[0]
}
}
else if(/verify/.test(path)){
page = "Verify";
}
else if(/problem/.test(path)){
page = "Problem";
}
else if(/noteligible/.test(path)){
page = "Not Eligible";
}
else if(/unavailable/.test(path)){
page = "Unavailable";
}
var selectedCard = bt_cookie('yrd_creditCardSelectorEligibility')
var balanceTransferOption = bt_cookie('yrd_creditCardBalanceTransfer')
var totalIncome = bt_cookie('yrd_creditCardTotalIncome')
return page + "|" + selectedCard + "|" + balanceTransferOption + "|" + totalIncome + "|" + results;
})();
What we have found happen sometimes, is that the page loads too quick for the cookie to be created. So we have had to change the way the Cookies get created. For instance you can change the code to create the Cookie as the user interacts with the form. ie: If the select a button or fill in a field. Capture the cookie there, rather than at the end of the page where the customer has to click the submit. Hopefully this makes sense?
I am having a problem with closing a pop window. My problem is unique in kind if I click Logout from the parent, it closes all the windows, but when I log out from a child, then I am logging out from Parent, so it does not close the other child windows that are open.
When I am logging out from a child and then I am logging out from a parent, I checked in console and it is not going inside the if block.
I am opening all the pop-ups like this -
function openpop1() {
sessionId = getURLParameters('requestID');
userName = getURLParameters('userName');
userId = getURLParameters('userId');
lvalue = getURLParameters('lValue');
lver = getURLParameters('lVer');
window.name = "parent";
var intWidth = screen.width - 10; //Adjust for the end of screen
var intHeight = screen.height - 80; //Adjust for the Icon Bar at the bottom of the window.
var strWinProp = " toolbar=no" //Back, Forward, etc...
+ ",location=no" //URL field
+ ",directories=no" //"What's New", etc...
+ ",status=yes" //Status Bar at bottom of window.
+ ",menubar=no" //Menubar at top of window.
+ ",resizable=yes" //Allow resizing by dragging.
+ ",scrollbars=yes" //Displays scrollbars is document is larger than window.
+ ",titlebar=yes" //Enable/Disable titlebar resize capability.
+ ",width="+intWidth //Standard 640,800/788, 800/788
+ ",height="+intHeight //Standard 480,600/541, 600/566
+ ",top=0" //Offset of windows top edge from screen.
+ ",left=0" //Offset of windows left edge from screen.
+ "";
awin = window.open(aUrl + userName + "&requestID=" + sessionId
+ "&userId=" + userId + "&lValue=" + lvalue + "&lVer=" + lver,'_blank',strWinProp);
}
function openpop2() {
sessionId = getURLParameters('requestID');
userName = getURLParameters('userName');
userId = getURLParameters('userId');
lvalue = getURLParameters('lValue');
lver = getURLParameters('lVer');
window.name = "parent";
var intWidth = screen.width - 10; //Adjust for the end of screen
var intHeight = screen.height - 80; //Adjust for the Icon Bar at the bottom of the window.
var strWinProp = " toolbar=no" //Back, Forward, etc...
+ ",location=no" //URL field
+ ",directories=no" //"What's New", etc...
+ ",status=yes" //Status Bar at bottom of window.
+ ",menubar=no" //Menubar at top of window.
+ ",resizable=yes" //Allow resizing by dragging.
+ ",scrollbars=yes" //Displays scrollbars is document is larger than window.
+ ",titlebar=yes" //Enable/Disable titlebar resize capability.
+ ",width="+intWidth //Standard 640,800/788, 800/788
+ ",height="+intHeight //Standard 480,600/541, 600/566
+ ",top=0" //Offset of windows top edge from screen.
+ ",left=0" //Offset of windows left edge from screen.
+ "";
bwin = window.open(bUrl + userName + "&requestID=" + sessionId + "&userId="
+ userId + "&lValue=" + lvalue + "&lVer=" + lver,'_blank',strWinProp);
}
And while log out I am calling
function onLogout() {
if (awin && !awin.closed) {
awin.close();
}
if (bwin && !bwin.closed) {
bwin.close();
}
sessionId = getURLParameters('requestID');
var rcvReq = getXmlHttpRequestObject();
rcvReq.onreadystatechange = function() {
if (rcvReq.readyState == 4 || rcvReq.readyState == 0) {
var data = rcvReq.status;
}
}
rcvReq.open("GET", logoutUrl +sessionId, true);
rcvReq.send(null);
window.location = loginPageUrl;
}
Now my problem is why is it not going inside the if block when I am logging out from the child and then the parent. I checked this by adding a breakpoint to these lines.
if (awin && !awin.closed) {
awin.close();
}
if (bwin && !bwin.closed) {
bwin.close();
}
I also checked whenever I am closing one pop-up the value of the both awin and bwin is getting set to undefined.
But why it happening. Somebody can help me on this?
EDIT :
Is this because if I am logging out I am setting a modal window on main page for user to tell the session is time out.
The code for that is here-
if (responseBodyFull == "Invalid Session Id passed") {
console.log("Invalid Session");
showModalBoxForInvalidSessionInfo();
}
and the function is defined like this -
function showModalBoxForInvalidSessionInfo(){
$("#modelView").dialog({
autoOpen : false,
modal : true,
buttons : [ {
text : "OK",
icons : {
primary : "ui-icon-heart"
},
click : function() {
$(this).dialog("close");
}
}]
});
$("#modelView" ).dialog("open");
$("#modelView").text("Session Timed Out. Please login again to access the Dashboard");
}
But anyway when we do console.log it is coming to the if part. So, I guess this should not be a problem.
I am trying to make a button on a form in Dynamics CRM, so that onClick the button show a dialog. The JS code I am using is as follows:
function addButton(attributename) {
if (document.getElementById(attributename) != null) {
var sFieldID = "field" + attributename;
var elementID = document.getElementById(attributename + "_d");
var div = document.createElement("div");
div.style.width = "19%";
div.style.textAlign = "right";
div.style.display = "inline";
elementID.appendChild(div, elementID);
div.innerHTML = '<button id="' + sFieldID + '" type="button" style="margin-left: 4px; width: 100%;" ><img src="/_imgs/ico_16_4210.gif" border="0" alt="Dial this number"/></button>';
document.getElementById(attributename).style.width = "80%";
document.getElementById(sFieldID).onclick = function () {onbuttonclick(); };
}
}
function onbuttonclick() { alert('Hi');}
This function is written in a JS Web Resource which gets triggered with form onload event of contact entity. Whenever the form load event is triggered I get the following error in a dialog box:
There was an error with this field's customized event.
Field:window
Event:onload
Error:undefined
kindly guide me towards the resolution.
The code is taken from a sample example.
This simply means that you have an error somewhere in your JavaScript.
A much better solution would be to use a ribbon button, and have that ribbon button call javascript, instead of messing with the DOM (which is unsupported). drop the following code into your ribbondiffxml:
<Actions>
<JavaScriptFunction Library="$[js library name]" FunctionName="[js function name]" />
</Actions>
Specifically, this should go into the CommandDefinitionNode.
Here is an example of what I do to open a dialog via javascript:
Ribbon.openDialogProcess = function (dialogId, EntityName, objectId) {
var url = Xrm.Page.context.getClientUrl() +
"/cs/dialog/rundialog.aspx?DialogId=" +
dialogId + "&EntityName=" +
EntityName + "&ObjectId=" +
objectId;
var width = 400;
var height = 400;
var left = (screen.width - width) / 2;
var top = (screen.height - height) / 2;
window.open(url, '', 'location=0,menubar=1,resizable=0,width=' + width + ',height=' + height + ',top=' + top + ',left=' + left + '');
}
so simply call that method in the RibbonDiffXML.
Following Script isn't working in CHROME browser, IE is Fine.
I've changed opener.document... to window.opener.document.... but same situation.
It's not closing windows and transfer data to parent page.
function mycoupon() {
window.open("my_coupon3.jsp?amt=<%=pay_price2%>",
'coupon_win',
'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes, resizable=no,width=780,height=540');
}
function sel_coupon(c_id, amt) {
var tot = opener.document.joinform.Org_totalprice.value;
tot = String(Number(tot) - Number(amt));
opener.document.joinform.totalprice.value = tot;
opener.document.joinform.coupon_id.value = c_id;
opener.document.joinform.all["tot"].innerHTML = maskNum(opener.document.joinform.Org_totalprice.value) + "USD - " + maskNum(amt) + " USD <b><font color='red'>Total : " + maskNum(tot) + " USD</font></b> ";
opener.cal_payment_money();
self.close();
}
Define a global variable and assign a reference to the new window then use it in your sel_coupon() function.
Here's an example:
var new_window_handle;
function mycoupon() {
new_window_handle = window.open("my_coupon3.jsp?amt=<%=pay_price2%>",
'coupon_win',
'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=yes, resizable=no,width=780,height=540');
}
function sel_coupon(c_id, amt) {
var tot = new_window_handle.opener.document.joinform.Org_totalprice.value;
tot = String(Number(tot) - Number(amt));
new_window_handle.opener.document.joinform.totalprice.value = tot;
new_window_handle.opener.document.joinform.coupon_id.value = c_id;
new_window_handle.opener.document.joinform.all["tot"].innerHTML = maskNum(new_window_handle.opener.document.joinform.Org_totalprice.value) + "USD - " + maskNum(amt) + " USD <b><font color='red'>Total : " + maskNum(tot) + " USD</font></b> ";
new_window_handle.opener.cal_payment_money();
self.close();
}
In case you're interested in the reason of this behavior, it's because IE assumes that the default window is the most recent one. So that's why when you run the code on IE it will try to find opener in the new window, but other browsers are a bit more strict (which is better in this case)
I have inherited a website! which was designed to work in IE and only IE it seems.. I've now been asked to make the site run in Firefox. I've fixed most of the bugs without any problems but this one has me stumped.
setTimeout(fDelayedFunc, 1000);
This line of Javascript, works fine in IE but in Firefox the function fDelayedFunc never fires. I've removed the setTimeout and the function wrapper and tried running the code as part of the main function. This works without any problems at all.
There is alot of code involved but here's the main but I'm having trouble with. If you'd like to see anymore of the code please let me know.
setTimeout(fDelayedFunc, 0);
//Save the current text box value
var vCurrentTBValue = vJQElement.val();
function fDelayedFunc() {
if (vJQElement.val() == vCurrentTBValue) {
alert("test");
//Get position list box should appear in
var vTop = vJQElement.position().top + 25;
var vLeft = vJQElement.position().left;
//Had to put a special case in for account due to the position co-ords being wrong. This is due to a css error
if (vHiddenFieldToWriteTo == "#ctl00_ContentPlaceHolder1_hfAccountCode") {
vTop = vJQElement.position().top + 58;
vLeft = vJQElement.position().left + 200;
}
else {
vTop = vJQElement.position().top + 25;
vLeft = vJQElement.position().left;
}
//Create div element
var vDivElement = $("<div id='divSearchBox' style='position:absolute; top:" + vTop + ";left:" + vLeft + "; z-index: 40000;'></div>");
//Create list box
var vListBox = $("<select id='lbResults' tabIndex='" + vJQElement.attr("tabIndex") + "' size='4' style='height:400px;'></select>");
//Bind a function to the list box which will select the item via either tab or enter
vListBox.bind("keydown", function() {
//Check if tab or enter has been pressed
if (event.keyCode == 9 || event.keyCode == 13) {
//Set hidden value to the selected items code
$(vHiddenFieldToWriteTo).val($(vListBox.find(":selected")).val());
//Create postback
$('#ctl00_ContentPlaceHolder1_wizNewConsignment_btnRefresh').click();
}
//Check if the up arrow has been pressed at the top of the listbox
else if (event.keyCode == 38 && $(vListBox.find(":selected")).val() == $(vListBox.find(":first")).val()) {
//Focus back on the search box
vElement.focus();
}
}).bind("dblclick", function() {
//Set hidden value to the selected items code
$(vHiddenFieldToWriteTo).val($(vListBox.find(":selected")).val());
//Create postback
$('#ctl00_ContentPlaceHolder1_wizNewConsignment_btnRefresh').click();
});
//Get search field
var vSearchText = vJQElement.val();
var vDepotID = $("#ctl00_ContentPlaceHolder1_wizNewConsignment_hfDepotID").val();
var vCustomerID = $("#ctl00_ContentPlaceHolder1_wizNewConsignment_hfCustomerID").val();
var vCountryID = $("#ctl00_ContentPlaceHolder1_wizNewConsignment_hfCountryID").val();
var vConsignee = vJQElement.attr("boolConsignee");
//Set a loading image in place until call completed
vJQElement.css("backgroundImage", "url(images/small-loader.gif)");
vJQElement.css("backgroundRepeat", "no-repeat");
vJQElement.css("backgroundPosition", "right");
//Make AJAX call
$.ajax({
type: "POST",
contentType: "application/json; charset=utf-8",
url: "NewConsignment.asmx/fGetAddressesAndIDs",
data: "{'strSearchText' : '" + vSearchText + "', 'intDepotID' : '" + vDepotID + "', 'intCustomerID' : '" + vCustomerID + "', 'intCountryID' : '" + vCountryID + "', 'boolConsignee' : '" + vConsignee + "'}",
dataType: "json",
success: function fGetAddressesAndIDsResult(GetAddressesAndIDsResult) {
//Make sure there are results
if (GetAddressesAndIDsResult != null && GetAddressesAndIDsResult != "") {
var vNumberOfResults = 0;
var vNumberOfLearntAddresses = 0;
var vLearntAddressUniqueID = "";
//Try to get results (first call will work on Linux and catch will work on Windows)
try {
//Check array exists (if this fails will go to catch)
if (GetAddressesAndIDsResult.d.length > 0) {
//Loop through the results
$.each(GetAddressesAndIDsResult.d, function() {
//Check for results
if (this.length > 0) {
//Evaluate JSON
var vAddress = eval("(" + this + ")");
//Create list item
var vOption = $("<option class='AddressOption' value='" + vAddress.uniqueID + "'>" + vAddress.briefDescription + "</option>");
//Find out number of learnt addresses
if (vAddress.uniqueID.indexOf("ConLA") != -1) {
vNumberOfLearntAddresses++;
vLearntAddressUniqueID = vAddress.uniqueID;
}
//Add list item to list box
vListBox.append(vOption);
//Mark result added
vNumberOfResults++;
}
});
}
}
catch (err) {
//Loop through the results
$.each(GetAddressesAndIDsResult, function() {
//Check for results
if (this.length > 0) {
//Evaluate JSON
var vAddress = eval("(" + this + ")");
//Create list item
var vOption = $("<option class='AddressOption' value='" + vAddress.uniqueID + "'>" + vAddress.briefDescription + "</option>");
//Find out number of learnt addresses
if (vAddress.uniqueID.indexOf("ConLA") != -1) {
vNumberOfLearntAddresses++;
vLearntAddressUniqueID = vAddress.uniqueID;
}
//Add list item to list box
vListBox.append(vOption);
//Mark result added
vNumberOfResults++;
}
});
}
//Check if only 1 learnt address was found
if (vNumberOfLearntAddresses == 1) {
//Auto select this address
//Set hidden value to the selected items code
$(vHiddenFieldToWriteTo).val(vLearntAddressUniqueID);
//Create postback
$('#ctl00_ContentPlaceHolder1_wizNewConsignment_btnRefresh').click();
}
//Add list box to div
vDivElement.append(vListBox);
//Check if any results exist in div
if (vNumberOfResults != 0) {
//Append div to page
$("body").append(vDivElement);
//Auto select first item
vListBox.find(".AddressOption:first").attr("selected", "true");
}
}
//Hide loading image
vJQElement.css("backgroundImage", "none");
},
error: function(XMLHttpRequest, textStatus, errorThrown) {
//Inform user of error
alert("An error occured, please try again");
//Hide loading image
vJQElement.css("backgroundImage", "none");
}
});
}
}
Try this:
setTimeout(function() { fDelayedFunc(); }, 0);
I took setTimeout(function () {function1();}, 1500) out from the addEventListener("load", () => {code})
it worked for me inside Firefox
try this : setTimeout('fDelayedFunc()', 0);