I am opening the window like this
var MyArgs = new Array(ParmA, ParmB, ParmC, ParmD, ParmE, ParmF);
var leftpost = getWindow_TotalWidth() - 1000 - 100;
var WinSettings1 = "dialogHeight:580px; dialogWidth:950px;edge:Raised; center:Yes; resizable:No; status: No;dialogLeft:" + leftpost + ";dialogTop:253px";
var MyArgs = window.showModalDialog("../Accounts/LedgerAdd.aspx?LedgerCode=" + MyArgs[1].toString().split("~")[0] + "&Popup=1", MyArgs, WinSettings1);
I would like to close the window based on condition. I have tried so many ways like
If Not Convert.ToDecimal(HidOpeningBalance.Value) = Convert.ToDecimal(TxtOpeningBalance.Text) Then
Dim LedgerID As Integer = Request.QueryString("LedgerCode")
Dim dtTransactionCount As DataTable = Grid.GetDataTable("sp_checkForAnyTransaction", LedgerID)
If dtTransactionCount.Rows.Count > 0 Then
LblError.Text = "You can not change Opening Balance after transactions made on this ledger."
Exit Sub
Else
Call FnUpdate()
Page.ClientScript.RegisterStartupScript([GetType](), "Javascript", "javascript:CloseWindow();", True)
End If
Else
LblError.Text = ""
Call FnUpdate()
Page.ClientScript.RegisterStartupScript([GetType](), "Javascript", "javascript:window.close();", True)
'Response.Write("<script language='javascript'>self.close();</script>")
'Page.ClientScript.RegisterStartupScript([GetType](), "Javascript", "javascript:CloseWindow();", True)
End If
my closeWindows function is
function CloseWindow() {
window.close();
}
If I call the function on onClientClick event, the popup is closing. But if I try to close it from code behind, the window is not closing. I have tried those three ways(I have commented in my code).
Please review this solution in the link provided.
http://forums.asp.net/t/993380.aspx?Close+Window+that+opens+with+window+showModalDialog
as you will see the solution became:
<base target="_self">
Related
I have tried numerious different approaches to my problem, but none of them seem to work out. I basically activate and deactivate users using a asp.net hyperlink and the problem is as soon as you do that, the page scrolls back up because of the postback it creates, so it will be annoying to scroll back down if you have a list of 1000 users. Here is the code iv'e been trying out without success!
// I use this variable for navigating the url for my hyperlink
var toggleUrl = "AdminListUsers.aspx?column=" + (IsClicked.FirstOrDefault().Key ?? "Name") + "&direc=" + (IsClicked.FirstOrDefault().Value) + "&a=chstat&q=" + id.ToString() + "&d=" + disabled + "&z=" + Server.UrlEncode(txtSearchFor.Text);
var hl = new HyperLink(); //These hyperlinks are the same
hl.Text = status;
hl.Style.Add(HtmlTextWriterStyle.Color, (disabled ? "red" : "green"));
hl.NavigateUrl = toggleUrl;
hl.Attributes.Add("onclick", "saveScroll(this);return true;");
cell.Controls.Add(hl);
tr.Cells.Add(cell);
cell = new TableCell();
cell.Width = new Unit("10%");
cell.Controls.Add(new LiteralControl("<nobr>"));
var linkbtn = new HyperLink //These hyperlinks are the same
{
//Here as you can see are my attributes for the hyperlink
NavigateUrl = toggleUrl,
Width = 16,
Height = 16,
CssClass = disabled ? "user-status-disabled" : "user-status-enabled"
};
linkbtn.Attributes.Add("id", "aButton_" + id);
ScriptManager.RegisterStartupScript(Page, typeof(Page), "ScrollToADiv", "setTimeout(scrollToDiv, 1);", true); // Not working
linkbtn.Attributes.Add("onclick", "window.scrollTo(0, location.hash);"); // Not working either
cell.Controls.Add(linkbtn);
cell.Controls.Add(new LiteralControl(" "));
As per my understanding, you could set the MaintainScrollPositionOnPostback to true in any of the below three ways.
Web.config Level => pages maintainScrollPositionOnPostBack="true" />
Page Level => <%# Page MaintainScrollPositionOnPostback="true" %>
Code Level => Page.MaintainScrollPositionOnPostBack = true;
Hope this Helps!!
EDIT
Code help for the comment below (assuming jQuery is being used):
$(".user-status-enabled").on("click", function() {
var $this = $(this);
var scrollPosition = $this.scrollTop();
$this.attr("href", $this.attr("href") + "&scrollPosition=" + scrollPosition);
});
And on the target screen, access this scrollPosition from Query String and set the scroll position on dom Ready
I'm trying to work on updating some code for a mobile web app, and I'm having difficulty getting a button to cause a pop-up as it should. I have the following (relevant) code:
#(Html.Kendo().MobileButton().Name("DropoffDone").Text("Confirm Dropoff").Url("ConfirmDropoff", "Drop", new {id = Model.DeliveryLocationId}).Events(ev => ev.Click("onClick")))
and, later in the same file under tags:
function onClick(ev) {
var currentDate = new Date();
var minuteToday = currentDate.getHours*60 + currentDate.getMinutes;
var minuteDeliv = #Model.DropTime.Hour*60 + #Model.DropTime.Minute;
var difference = minuteDeliv-minuteToday;
var r = false;
if(difference>15){
r = confirm("Message Here");
if(!r){
ev.preventDefault();
}
}
}
The button works fine and it seems to call the javaScript (I tested with a sample alert) but it never seems to actually get to the inside of the 'if' statement. I would like it to pop up with a confirm message, allowing the user to cancel the action. Where is the code not functioning properly? Thank you all in advance for your help.
I enter to browser this link
https://google.com.vn;
Google redirect to https://www.google.com.vn;
I want alert full url redirect.
I used this code:
processNewURL: function(aURI) {
var tabIndex = gBrowser.tabContainer.selectedIndex;
var referredFromURI = gBrowser.tabContainer.childNodes[tabIndex].linkedBrowser.webNavigation.referringURI.spec;
alert(referredFromURI);
},
But it always alert https://www.google.com.vn,
and I tested with some short link example bit.ly/R9j52J . It isn't ok.
Please help me.
this works, i also show 2 methods to get to webNavigation. the second method is just longed winded way to teach other stuff, recommended way is method 1.
var processNewURL = function(e) {
console.log('e:', e);
var win = e.originalTarget.defaultView;
//start - method 1 to get to webNav:
var webNav = win.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation);
var referredFromURI = webNav.referringURI;
//end - method 1
//start - method 2 long winded way:
/*
var domWin = win.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIWebNavigation)
.QueryInterface(Ci.nsIDocShellTreeItem)
.rootTreeItem
.QueryInterface(Ci.nsIInterfaceRequestor)
.getInterface(Ci.nsIDOMWindow);
var tab = domWin.gBrowser._getTabForContentWindow(win);
//console.log('tab:', tab);
var referredFromURI = tab.linkedBrowser.webNavigation.referringURI;
*/
//end - method 2
if (referredFromURI != null) {
win.alert('referred from:' + referredFromURI.spec);
} else {
win.alert('not redirected');
}
}
gBrowser.addEventListener('DOMContentLoaded', processNewURL, false);
I'm trying to launch a popup from certain pages. I want users to see the popup only when:
a) they close the browser tab
b) they hit the browser's Back button
c) they go to a page other than the next step in the purchase path - basically, when they go to any URL that does not contain the string "/checkout/".
I've looked at popup examples that load body onUnload, and that's a bit too global. I just want a popup - a true actual popup - to launch if they try to leave the checkout path.
I've looked at several questions on StackOverflow, but none of them quite seem to answer my question. The onBeforeUnload mentioned in this answer https://stackoverflow.com/a/3753963/1634459 might work...MIGHT...but I'm not totally sure how to implement it with the conditions I listed above.
...help?
Here's the popup window code I'd like to use:
<script language="javascript" type="text/javascript">
var win=null;
function NewWindow(mypage,myname,w,h,scroll,pos){
if(pos=="center"){LeftPosition=(screen.availWidth)?(screen.availWidth-w)/2:50;TopPosition=(screen.availHeight)?(screen.availHeight-h)/2:50;}
settings='width='+w+',height='+h+',top='+TopPosition+',left='+LeftPosition+',scrollbars='+scroll+',location=no,directories=no,status=no,menubar=no,toolbar=no,resizable=no';
win=window.open(mypage,myname,settings);
if(win.focus){win.focus();}}
function CloseNewWin(){if(win!=null && win.open)win.close()}
window.onfocus=CloseNewWin;
</script>
Here you go; I wrote this for the marketing team at a previous job. You should be able to adapt it pretty easily; just update the URL and params as appropriate.
This code will open a popup when the user leaves the page, unless they leave by submitting the checkout form. (If you have more than one form on the page, which you shouldn't in a checkout flow, you will need to fix that as well.)
var nag = function () {
return {
// assume the user is going to leave, get ready to pounce!
doWant: true,
// FALCON PUNCH
deploy: function () {
if (nag.doWant) {
var width = 449;
var height = 298;
args = "width=" + width + ",";
args += "height=" + height + ",";
args += "location=0" + ","
args += "menubar=0" + ","
args += "resizable=1" + ","
args += "scrollbars=0" + ","
args += "status=0" + ","
args += "titlebar=0" + ","
args += "toolbar=0" + ","
args += "hotkeys=0"
var demo_window = window.open("YOUR_URL", "main", args);
try {
demo_window.focus();
} catch (err3) { };
}
},
// oh, off to step 2? that's cool. carry on.
ignore: function () {
nag.doWant = false;
}
}
} ();
window.onunload = nag.deploy;
document.forms[0].onsubmit = nag.ignore;
If you want to be able to STOP the user from leaving the page, I can help you with that update.
Ok I know this is going to sound weird but it is what the client wants. I am working within a popup and when a user clicks on a datagrid cell within a certain column it will popup a html table with data. I have the second popup to display but it does not get focus. This is currently the code I am using to create the second popup. Any help to get the focus on this second popup would be great.
function onCellClick() {
var cmGrid = igtbl_getGridById("countermeasureDetailsGrid");
var cmCellID = cmGrid.ActiveCell.split("_");
if (cmCellID[3] === "3") {
var countermeasureID = igtbl_getCellById("countermeasureDetailsGrid_rc_" + cmCellID[2] + "_0").getValue();
var recordType = igtbl_getCellById("countermeasureDetailsGrid_rc_" + cmCellID[2] + "_4").getValue();
_crfPopupWindow = new crfPopupWindow(countermeasureID, recordType);
_crfPopupWindow.open();
_crfPopupWindow.focus();
}
}
function crfPopupWindow(countermeasureID, recordType) {
var crfPopup = new WindowDef();
crfPopup.target = "CRF_Popup.aspx?countermeasureID=" + countermeasureID + "&" + "recordType=" + recordType;
crfPopup.windowName = "CRFPopup";
crfPopup.toolBar = "no";
crfPopup.resizable = "yes";
crfPopup.scrollbars = "yes";
crfPopup.location = "yes";
crfPopup.width = 350;
crfPopup.height = 400;
return crfPopup;
}
EDIT: Solution
<script type="text/javascript" language="javascript">
function init() {
window.focus();
}
</script>
Have you checked that the 2nd popup has higher z-index CSS property?
First popup can have z-index of, say, 1000, but the second should have then 1001.
window.focus on page load This works