Telerik RadMenu Click To Open and Close when clicked to next page - javascript

Hi im having problem with my radmenu. I want it to click to open and not open as you hover. I have set the clicktoopen = "true" already. Now the problem is when i click, it navigate to the respective requested page but the menu doesn't close.
<script type="text/javascript">
function OnClientItemClicking(sender, args) {
if (args.get_item().get_isOpen() == true) {
args.set_cancel(true);
args.get_item().close();
}
else {
}
}
</script>
<script type="text/javascript">
function OnClientMouseOverHandler(sender, eventArgs) {
if (eventArgs.get_item().get_parent() == sender) {
sender.set_clicked(false);
}
}
function onClientItemClicked(sender, args) {
}
</script>

Related

Run function after closing popup window in asp.net

How can I run a function after closing the popup window?
This is my button click to open the popup window:
ImageButton btnEdit = (ImageButton)sender;
GridViewRow row = (GridViewRow)btnEdit.NamingContainer;
string url;
url = "Add-Bank.aspx?a=E&id=" + txtEmployeeCode.Text.Trim() + "&acc=" +
((HiddenField)row.FindControl("hidRecID")).Value;
Response.Write("<script>window.open('" + url + "',400,600);</script>");
And in my popup window, close button code is:
this.ClientScript.RegisterClientScriptBlock(this.GetType(), "Close", "window.close()", true);
When I close the popup window how can I run the specific function or button click event?
What I tried is so far
I created one click even called btnRefresh:
protected void btnRefresh_Click(object sender, EventArgs e)
{
LoadData();
}
I tried to run this event from popup window but it's not hitting the event as:
<script type="text/javascript">
$(document).ready(function () {
var cpframe = top.document.getElementById('contframe');
if (cpframe) {
cpframe.contentWindow.document.getElementById('Main_btnRefresh').click();
}
});
</script>
thanks in advance.

call javascript function from another javascript function on confirmation

I am showing a Confirmation modal popup where user can either select yes or no and when user clicks yes i want to show another modal popup
this is my script for confirmation:
<script type="text/javascript">
function openModalConfirm(message, header, url) {
$(<%= myModal.ClientID%>).modal('show');
$('#lblMasterMessage').html(header);
$('#lblMasterbodyMessage').html(message);
$('#<%= BtnYes.ClientID %>').attr('onclick', "$('#myModal').modal('hide');setTimeout(function(){" + $(sender).prop('href') + "}, 50);");
$(<%= myModal.ClientID%>).on('hidden.bs.modal', function (e) {
if (url != '') {
window.location = url;
}
});
return true;
}
</script>
and this is the moadal popup which i want to show after the above popup is shown
<script type="text/javascript">
function openModal(message, header, url) {
$('#myModal').modal('show');
$('#lblMasterMessage').html(header);
$('#lblMasterbodyMessage').html(message);
$('#myModal').on('hidden.bs.modal', function (e) {
if (url != '') {
window.location = url;
}
});
}
</script>

On close tab ask for unsaved changes and then reload the page - How?

I've come across a nasty website that managed to refresh the page every time I tried to close the tab. Basically you couldn't close that page. I got around it by disabling javascript on that page.
How do they do it?
I've tried location.replace inside onbeforeunload and it doesn't work:
window.onbeforeunload = function(e) {
window.location.replace(window.location.href);
};
Here is the source of the page in question, where I don't get how they do it:
<script type="text/javascript">
function c(b)
{
document.write(b);
}
function wrapped3(d)
{
return d.replace(/(.)(.)/g, '%$1$2');
}
function wrapped(b)
{
var tmp = window['decodeURI' + 'Component'];
return tmp(wrapped3(b))
}
function show_page(a)
{
c(wrapped(a)
.split('{{addr}}').join('//ip')
.split('{{country}}').join('Great Britain')
.split('{{region}}').join('London, City of')
.split('{{city}}').join('London')
.split('{{ltude}}').join('//latitude')
.split('{{referrer}}').join('//url here')
);
}
show_page('//long string here');
</script>
window.onbeforeunload is the correct solution, here is an example:
var popit = true;
window.onbeforeunload = function() {
if(popit == true) {
popit = false;
return "Are you sure you want to leave?";
}
}
http://jsfiddle.net/SQAmG/3/

pop up of confirmation box when closing tab/window only

Hello i need a pop up message of confirmation when going to close browser/tab only, not when going to click on any link. In my code, it gave me pop up message when i close browser/tab as well as click on any link, which i don't want. I really have no idea how to do it. Can anyone please help me.
My code is-
<body>
<div id="copyright">
<div class="moduletable copyright ">
<div class="custom copyright">
<p>
<span class="copy">© Copyright 2008</span>
Inc. All rights reserved. </p>
</div>
</div>
</div>
</div>
</div>
<br class="clear" />
</div>
</div>
<script language="JavaScript">
window.onbeforeunload = bunload;
function bunload(){
dontleave="Are you sure you want to leave?";
return dontleave;
}
</script>
</body>
</html>
Try this:-
<body>
click here
<script language="JavaScript">
window.onbeforeunload = function () {
return "Are you sure?";
}
function prevent() {
window.onbeforeunload = function () { };
};
</script>
</body>
Your said event onbeforeunload works perfectly.
window.onbeforeunload = function(e) {
return 'Dialog text here.';
};
See it in action.
Tl/Dr
The below code will be completely pseudo-code describing the method you'll need to run through to get this to work.
The first step is that you'll need to add an identifier to all "internal" links within your site. For example, if your page is contact, and there is a link to that page form your home page, you need to distinguish between the types of pages.
function confirmExit() {
if (!internal_link) {
// random shit..
return message
}
}
var key = "internal_link";
window[key] = false;
var message = "Your custom message. Are you sure you want to blah?";
window.onbeforeunload = confirmExit;
internal_link = false;
$(document).ready(function () {
if (!window.location.origin) {
window.location.origin = window.location.protocol + "//" + window.location.hostname
}
$("a").each(function () {
if ($(this)[0].href.indexOf(window.location.origin) == 0) {
if ($(this).attr("onclick") == "undefined") {
$(this).attr("onclick", key + " = true")
} else {
if ($(this).attr("onclick")) {
var e = $(this).attr("onclick");
$(this).attr("onclick", e + " " + key + " = true")
} else {
$(this).attr("onclick", key + " = true")
}
}
} else {
if ($(this).attr("onclick") !== key + " = true" || $(this).attr("onclick") == "undefined") {
$(this).attr("onclick", key + " = false")
}
}
});
});
The above is what I've used previously and it's worked perfectly. Basically what it does is adds an attribute to internal links (links within your site), then when users navigate around your site, the onbeforeunload runs the confirmExit() function and checks if the internal_link is false, if so, it shows the message otherwise it navigates through the site.
Nothing work for me but I made it with some combinations of the above code and from other forums.
<script language="JavaScript">
window.onbeforeunload = function () {
return "Are you sure?";
};
$(document).ready(function () {
$('a').click(function () {
window.onbeforeunload = null;
});
$('form').submit(function () {
window.onbeforeunload = null;
});
});
</script>
The onbeforeunload event will be fired when you submit a form too, so we need to prevent the event.

Confirmation box before closing tab, not when page is reloaded

My client requirement is to give an alert message when browser tab of my web application is closed. It can be done using JavaScript onunload or onbeforeunload event.
But there are many drop-down boxes in my application and selecting some of drop-down boxes, page needs to be reloaded. During this reloading each time onunload or onbeforeunload is fired and alert message is displayed. I want to stop firing this onunload or onbeforeunload event on reloading page but display alert message when browser tab is closed. If there were any changes in URL, it would be helpful. But my URL is not changed.
I know there is no direct JavaScript event support for this situation. Can anyone suggest alternative solution?
Update:
<script language="JavaScript1.2" type="text/javascript">
var g_isPostBack = false;
function windowOnBeforeUnload()
{
if ( g_isPostBack == true )
return; // Let the page unload
if ( window.event )
window.event.returnValue = 'Are you sure?'; // IE
else
return 'Are you sure?'; // FX
}
window.onbeforeunload = windowOnBeforeUnload;
</script>
Code behind:
protected void Page_Load(object sender, EventArgs e)
{
this.ClientScript.RegisterOnSubmitStatement(this.GetType(), "OnSubmitScript", "g_isPostBack = true;");
}
try the below code and update us if this is your requirement.
<script type="text/javascript">
var new_var = true;
window.onbeforeunload = function () {
if (new_var) {
return "you have unsaved changes, if you leave they will be lost"
}
}
function unhook() {
new_var = false;
}
</script>
faced the same problem try this script
<script language="JavaScript" type="text/javascript">
window.onbeforeunload = confirmExit;
function confirmExit() {
return "You are about to exit the system before freezing your declaration! If you leave now and never return to freeze your declaration; then they will not go into effect and you may lose tax deduction, Are you sure you want to leave now?";
}
$(function() {
$("a").click(function() {
window.onbeforeunload = null;
});
$("input").click(function() {
window.onbeforeunload = null;
});
});
</script>

Categories

Resources