Hi All,
Is there any way to find the event is browser back button click?
I need to show an alert when user clicks on browser back button? I tried using the following code but alert is showing for every event on this page. -
window.onbeforeunload = function(evt)
-
{
-
if (typeof evt == 'undefined')
-
evt = window.event;
-
-
-
if(evt)
-
{
-
-
return "If you leave this page, your information will not be updated.";
-
}
-
}
-
20 41197
Hi bHappy,
In IE, you can find with the help of PageX, PageY but in Mozilla its difficult to findout the click of browse button. Instead you can use the window.onbeforeunload handler itself. You use this handler for only some pages where you want the user to save the datas are do something before he navigate to other page.
Hi,
Thanks for ur reply,
I am using this code in only one page where i had save, update, cancel buttons and some links also available in left side menu. My problem is alert msg is showing if i click any link or button also.
Plz some body help me...
Thanks.
well, all these elements trigger this event (insofar the behaviour is correct). basicly pressing the back button is like using a link… maybe you can differentiate by the event target.
Hi,
Thanks for ur reply.
Can u provide me any examples or sample code.
Thanks.
I would have to write some … don’t know when I’ve got time for that.
Hi,
I modified my code like this: - var links = document.getElementsByTagName('a');
-
for (var i = 0; i < links.length; i++)
-
{
-
links[i].onclick = setGlobal;
-
}
-
function setGlobal()
-
{
-
window.linkClicked = true;
-
}
-
window.onbeforeunload = function()
-
{
-
if (typeof window.linkClicked == 'undefined' || !window.linkClicked)
-
{
-
return "Are you sure?"
-
}
-
}
It is working fine If page contains only links and buttons. But in my page i had some links, buttons and links under lists(<ul>).
For the below code my javascript is working fine. - <input id="Submit1" onclick="setGlobal();" type="submit" value="submit" />
-
<a href="#">Click Here</a>
My javascript is not working fo the below code - <ul>
-
<li><a href="/ConsoleManagement/default.asp">Place An Order</a></li>
-
<li><a href="/ConsoleManagement/history.asp">View Order History</a></li>
-
<li><a href="/ConsoleManagement/profile.asp">Update My Information</a></li>
-
</ul>
Plz any solution?
when do you call the script? (if you call it before the elements are created by the browser, the event doesn’t get attached)
Few elements are creating after javascript, so my javascript is not working.
Thanks for ur idea.
usually any such thing that is to apply to elements or nodelists of the document should be triggered by the window.onload event (because you can be sure, that then all the elements exist).
Hi,
Thanks for ur reply. Now my javascript is working fine. Other than this 'do u have any other solution'?
Thanks once again.
at last I’ve found a way to differentiate between a hardcoded link and the back button. apply the onbeforeunload event (window), use the click event (link) to remove the onbeforeunload event. because the back button is not part of the document and the click event being triggered before the onbeforeunload event, clicking on the back button cannot remove onbeforeunload.
I could not able to understand what you are trying to say. Can you please explain me in detail. A piece of code will be better.
- // execute onbeforeunload when leaving the page
-
// by whatever means (links, buttons, back, forward, reload, …)
-
window.onbeforeunload = function(evt)
-
{
-
// do whatever you need here
-
}
-
-
// get the links (I used only one for demo)
-
var link = document.getElementById("test");
-
-
// remove the onbeforeunload event from the link
-
link.onclick = function() { window.onbeforeunload = null; }
now your beforeonload function/code is only triggered by back, forward, reload.
Thanks for ur reply.
I have placed the javascript code at the bottom of the page.It is working fine, but my page will take 1 minute time to load, mean time if end user clicks back button then alert will not show, because javascript may/maynot be loaded.
If i place this code at the top of the page then for every event alert will show, because no controls are created yet.
Please provide me any solution.....
Thanks.
what do you need to load for taking so long?
Actually my page is built by 2 different projects (using virtual directory). Header and footer is common for all pages in the site. I had totally 22 web sites which have same functionality. So business logic code is placed in one separate project and all 22 projects are refering this common project. so i need to place my javascript at the bottom of the page because in footer also some hyper links are exists. So my page is taking some time to load.
Note: Technology is 'ASP'. (Viryually link 2 projects).
does that mean the server taking so long to compute some html or is it just a huge amount of pictures?
We are appreciating your patience.
All controls in the page will populate dynamically, because all websites use the same asp page. Based on the domain name contents will be retrived from database. so it is taking some time to load the page.
then you should optimize your DB code. I never encountered such long delays (ok, I’m not having complex code, though)
Here Heder and Footer is populated from one project and remaning contents are populated by another project, so it is taking some time.
Sign in to post your reply or Sign up for a free account.
Similar topics
by: Liqun Xu |
last post by:
Hallo NG,
I created a Button with Click-Event dynamically:
System.Web.UI.WebControls.Button bt_1 = new Button();
bt_1.Click += new EventHandler(bt_1_click);
and I implemented the Funktion...
|
by: Bin Song, MCP |
last post by:
Hi all
I got a strange problem
In my webform, I have a server-side Button "btnDisable" to save some data and enable or disable all other fields in this form based on the data.
The logic is: on...
|
by: zdrakec |
last post by:
Hello all:
I note in my application, that when I use
Server.Transfer("somepage.aspx"), when the new page is loaded, and I
click the Back button on the browser, that the previous page, when it...
|
by: tshad |
last post by:
Is there an event that gets fired when the Browsers Back Button is pressed?
I want to save the clients entry if they should hit the back button by
accident.
Thanks,
Tom
|
by: one man army |
last post by:
Hi All-
I am new to PHP. I found FAQTS and the php manual. I am trying this
sequence, but getting 'no zip string found:'... PHP Version 4.4.0
$doc = new DomDocument;
$res =...
|
by: hemant.singh |
last post by:
Hi all,
I am trying to get a way by which I'll know exactly when user goes out
of my site by clicking on close button in browser, So that w/e user
click close button in browser, I can send a...
|
by: joe |
last post by:
Logout question
I use a session to store the login information, say Session("Login") = success
and use page_load to test the session("Login") success or not
say If Session("Login") <success...
|
by: axxon |
last post by:
Hi guys! I am at my wits end detecting which one of the dymically loaded button fired the click event(since they all have same ID and text value)
Heres the scenario:
I have created a loop to read...
|
by: Gouri.Mahajan7 |
last post by:
Hello,
I am new to asp.net. Can anybody please tell me which event
is fired when we close the browser. I want to
remove some resources when the browser close button is pressed.
Thanks in advance....
|
by: ryjfgjl |
last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: nemocccc |
last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: Hystou |
last post by:
Overview:
Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
|
by: agi2029 |
last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
| |