I have use below code to back for the previous page, but it's not working. the alert box still popup even i click ok on the page.
actually there have 3 page include this windows page code. 1st page is user need to fill up the form is name redeem_newcust.asp and the action should be save all the data into the database named redeem_newcustDB.asp. In page redeem_newcustDB.asp have one code to select option for type of redemption then this page will point action to the page redeem_newprocess.asp with is included as below code. Means when user click on type of redemption not equal to "Birthday Pack - PDV RM50" then it should be back to the previous page that means page redeem_newcustDB.asp.
It's possible to having back to that previous page..? Should b need to bring all the value?
Please help, thanks
If redeemtype = "Birthday Pack - PDV RM50" then
Response.Redirect("redeem_newbirth.asp?cardno="&BlinkCard&"&redeemtype="&redeemtype&"")
Else
%>
<script language="javascript">
<!--
window.alert ("Please choose Type of Redemption");
window.history.go(-1);
//-->
</script>
<%
End If
%>
Use: window.history.back() instead .go();
http://www.w3schools.com/jsref/met_his_back.asp
or use:
window.alert("Please choose Type of Redemption");
setTimeout(function(){
window.history.go(-1);
},500);
I would always avoid using alert(), since it kills script in some Browsers. I would open() a new window and ButtonElement.onclick use location =.
Note:
window is implicit, so you don't need to write window.open() or window.location. Additionally, it's fine to leave off .href when referring to location.href
Related
There are two pages, and I want to show an alert on the first page when the user comes back from second page to first page.
I know how to go back to first page by: window.location.href
and also by: window.history.back().
But I don't know how to show an alert once it's backed?
You can simply achieve it using localStorage or sessionStorage.
// Page 1
const visited = localStorage.getItem("visited")
if(visited) alert("//Do something here, why you came back")
else localStorage.setItem("visited", "visited")
You can give the url a parameter and use it to check whether an alert message should be fired.
For example: window.location.search -> '?visited=true'
I have to do some kind of operation on the page refresh or reload. that is when I hit next page or Filter or refresh on the grid. I need to show some confirmation box over this Events.
is there any event which can tell you page is doing filer? refresh or paging? using javascript?
Thanks
If it is refreshing (or the user is leaving the website/closing the browser), window.onunload will fire.
// From MDN
window.onunload = unloadPage;
function unloadPage()
{
alert("unload event detected!");
}
https://developer.mozilla.org/en/DOM/window.onunload
If you just want a confirmation box to allow them to stay, use this:
window.onbeforeunload = function() {
return "Are you sure you want to navigate away?";
}
You can create a hidden field and set its value on first page load. When the page is loaded again, you can check the hidden field. If it's empty then the page is loaded for the first time, else it's refreshed. Some thing like this:
HTML
<body onLoad="CheckPageLoad();">
<input type="hidden" name="visit" id="visit" value="" />
</body>
JS
function CheckPageLoad() {
if (document.getElementById("visit").value == "") {
// This is a fresh page load
document.getElementById("visit").value = "1";
}
else {
// This is a page refresh
}
}
There are some clarification notes on wrestling with this I think are critical.
First, the refresh/hidden field system works on the beginning of the new page copy and after, not on leaving the first page copy.
From my research of this method and a few others, there is no way, primarily due to privacy standards, to detect a refresh of a page during unload or earlier. only after the load of the new page and later.
I had a similar issue request, but basically it was terminate session on exit of page, and while looking through that, found that a browser treats a reload/refresh as two distinct pieces:
close the current window (fires onbeforeunload and onunload js events).
request the page as if you never had it. Session on server of course has no issue, but no querystring changes/added values to the page's last used url.
These happen in just that order as well. Only a custom or non standard browser will behave differently.
$(function () {
if (performance.navigation.type == 1) {
yourFunction();
}
});
More about PerformanceNavigation object returned by performance.navigation
dearest experts.
You helped me with this issue on this link below previousl:
How to I redirect to another page *after* printing document?
Things seemed to be working fine until this morning we discussed that users were submitting duplicate entries.
The reason for this is that once the user clicks to Submit their request,they are presented with a button that says, ">>>Click Here To Print Form<<<<".
Users are required to print this form but for some reason, they forget to do so.
In the event that they forget to print this form, they are taking back to the input screen with boxes still retaining the data they initially entered.
Is there a way to redirec them to results.aspx page, whether they print the form or not?
Please see current code and many thanks in advance.
<script type ="text/javascript">
function doPrint() {
var printContent = document.getElementById("pdmyop");
window.print(printContent);
document.location.href = "results.aspx";
}
</script>
**********************************
<asp:Button ID="btnPrint" runat="server" Text=">>>Click Here To Print Form<<<<" OnClientClick="doPrint(); return false;" />
You can add this script at the end of the SubmitForm procedure:
String script = String.Format("window.print(); window.location = '{0}';", ResolveClientUrl("~/results.aspx"));
ClientScript.RegisterStartupScript(insub.GetType(), "print", script, true);
I hope you can translate this code from C# to VB. If insub placed in an UpdatePanel use ScriptManager instead of the ClientScript.
Be warned, that this code doesn't work in Chrome (as well as any code those make redirect onto different page before document printed)
Hi
I have created quiz application. once login entered by user then test will start after he will submit the test then results will appear. If user clicks back button in toolbar then again earlier questions appears, it should not appear as he already given the test.
Asp.net c#
Thank you.
You can maintain a session variable where you can store a value. Then when your user submits a test, you can check that value on a test page and then decide whether to show test or not.
If you want to restrict on the client side, there is one work around here...
Just put this javascript on the html section of aspx page above head section.
This causes every back to return with a forward.
<script type = "text/javascript" >
function disableBackButton()
{
window.history.forward();
}
setTimeout("disableBackButton()", 0);
</script>
You could have them take the quiz in a popup window with all of the buttons and bars hidden
<script type="text/javascript" language="javascript">
function ShowQuiz(QuizID) {
var newWin = window.open("Quixz.aspx?QuizID=" + QuizID, "Quiz", "menubar=0,resizable=2,width=620,height=500,scrollbars=1");
newWin.focus();
}
</script>
Take Quiz
I would also recommend putting an intermediate page after each that just redirects to the next page. As well as the Javascript that Muhammad Akhtar included on each quiz page.
I wrote a javascript function to go to a particular page if it came from a particular page.
Function:
function proceed()
{
if( document.referer == "http://abcd.com/index.php?action=SignUp")
{
return document.location.href = "http://abcd.com/editprofile.php?action=editprofile";
}
}
Submit button for a form in current page(b):
What i want is to go through a sequence of pages a->b->c , where a is previous , b is current , and c is next in my case. b has a form, on submitting values to the form, it should also call the javascript function and then go to the page c.
Can anybody help me find out where is the mistake? Any help would be highly appreciated. Thanks.
Since you have a form I guess there's also some php/cgi script that will handle the form's data!?
In that case your form won't continue to that script if you override your submit button via javascript in such way that it loads another page (other cases like validation do work that way, of course).
So
Your submit button has spaces next to the onclick attribute: onclick = "javascript... should be onclick="javascript....
Your function proceed() should return true for the submit to perform.
Even after all syntax correction, there's still something odd. After all, you can only give one "next page" functionality to your submit button. So what should the form call:
your php or cgi script? Then you can build a redirect to page "c" into that one.
your page "c"? Then what do you need the form for?
both, but independently? In that case I suggest a javascript popup from proceed() displaying page "c" and returning true so the form continues with its script.
To be more accurate you will have to provide more of your application's code.
Solution seems to be the following. Use the submit attribute for your button:
<button type="button" onclick="proceed(); alert('You are not authorized to execute this action!');">Click Me!</button