|
The code below is suppose to auto logoff a user after 30 seconds. The problem is it works fine with 32 bit browsers but not at all in 64 bit browsers. The countDown() function gets called but it never executes the window.location.
Any assistance would be appreciated!
<script type='text/javascript'>
var secondsRemaining = 30;
var mhcTimer;
function countDown() {
secondsRemaining -= 1;
if (secondsRemaining <= 0) {
secondsRemaining = 0;
window.location='login.aspx';
}
}
function startAutoLogoff() {
if (mhcTimer) {
return false;
}
else
{
mhcTimer = setInterval('countDown();', 1000);
}
}
startAutoLogoff();
</script>
|
|
|
|
|
my guess is that the assignment operator -= is not working properly and is probably only assigning the value of 1 to each time it executes.
have you tried debugging your javascript code and inspecting the value after the assignment operator?
as if the facebook, twitter and message boards weren't enough - blogged
|
|
|
|
|
One possibility is that other task running in the machine are killing the setInterval - this happens very often in Internet Explorer to the extent that the standard advice is to never use setInterval but to use setTimeout even though it is slightly more difficult.
If you are running in a 64 bit processor, then I guess that performance is not an issue. But there are a few places where the JavaScript could be improved.
* The only way that the secondsRemaining can go negative is if you run startAutoLogoff twice as you initialise the secondsRemaining at the top and not at the start of the auto logoff and you test for that condition.
* There is a -= 1 idiom: it is the pre-/post-decrement operator (-- ). Just because some gurus don't like it in the middle of expressions, does not mean that it is verbotem as a stand alone construct.
* Since JavaScript 1.2 (c 1998), the setInterval and setTimeout methods have supported functions as arguments as an alternative to expressions. These are more efficient, support closures, and prevent faux eval expressions which most gurus hate.
* You have a lot of global variables (secondsRemaining , mhcTimer , countDown , and startAutoLogoff ). It is possible that you may have a name clash somewhere else in your code that is causing the issue that you describe.
Here is my equivalent code (I know that my layout and style offend some people):
function startAutoLogoff()
{
if (! startAutoLogoff.mhcTimer)
{
startAutoLogoff.secsRemaining =
startAutoLogoff.timeoutTime;
startAutoLogoff.mhcTimer =
window.setTimeout( startAutoLogoff.countDown, 1000 );
}
}
startAutoLogoff.countDown =
function( )
{
if (--startAutoLogoff.secsRemaining)
startAutoLogoff.mhcTimer =
window.setTimeout( startAutoLogoff.countDown, 1000 );
else
window.location ='login.aspx';
};
startAutoLogoff.mhcTimer = false;
startAutoLogoff.timeoutTime = 30;
startAutoLogoff.secsRemaining = startAutoLogoff.timeoutTime;
startAutoLogoff();
|
|
|
|
|
guys;
I need to add a hidden input at run time. I used the following code:
var hiddenInput = document.createElement('input');
hiddenInput.type = 'hidden';
hiddenInput.name = 'hiddenInput';
hiddenInput.value = 'somevalue'
this code should generate the element:
<input type="hidden" name="hiddenInput" value="somevalue" />
but it generates the element:
<input type="hidden" propdescname="hiddenInput" value="somevalue" />
could you please help me with this?
Help people,so poeple can help you.
|
|
|
|
|
This is an unfortunate but known issue. If you run this code in IE it will actually create an input with the code below:
<input type="hidden" submitName="hiddenInput" value="somevalue" />
The only way I know to fix it is appending the HTML code manually to the parent node in the dom tree. That way you will be able to set the name properly.
|
|
|
|
|
thank you, sir.
100
Help people,so poeple can help you.
|
|
|
|
|
hai all
i want to validate the content page using javascript external file.
i keep 5 text box in content page.i want to validate the textbox like
fields must not blank,
characters only allowed for name,state,country.
numbers only allowed for age,pincode
email validation etc.
i want to validate the textboxes in content page using javascript external file.
how to do these...plz send javascript code...thanks in advance...
|
|
|
|
|
Firstly, Why did you put your question in a code block, doesn't look very clever............
Ok, so back to your question;
You can use the object onChange to call a javascript function to validate the content as each element changes.
You could also use a button when you submit to check each element. The code below is a sample to help you get going, but there are heaps of examples on the net. You could take all the javascript out of the lower script block and place it in a reference file as shown in the upper script block entry
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<title></title>
<script type="text/javascript" src="js/thejsfile.js"></script>
</head>
<body>
<table>
<tr><td>Name:</td><td><input id="textName" type="text" onchange="validateName()"/></td><td id="nameValidMessage"></td></tr>
<tr><td>Age:</td><td><input id="textAge" type="text" onchange="validateAge()"/></td><td id="ageValidMessage"></td></tr>
</table>
<input id="ButtonGo" type="button" value="Go" onclick="go_click()"/>
<script type="text/javascript">
function validateAge() {
var valid = false
//write you code to validate the age
//set valid to true if all ok
if (textAge.value == "99") { valid = true; }
//update the page message
if (!valid) {
ageValidMessage.innerHTML = "Invalid Age";
}
else {
ageValidMessage.innerHTML = "";
}
return valid
}
function validateName() {
var valid = false
//write you code to validate the name
//set valid to true if all ok
if (textName.value == "Dave") { valid = true; }
//update the page message
if (!valid) {
nameValidMessage.innerHTML = "Invalid Name";
}
else {
nameValidMessage.innerHTML = "";
}
return valid
}
function go_click() {
var valid = false
//Do a validation of Name and Age
valid = validateName() && validateAge()
if (valid) {
//Do what you need to if all ok
}
}
</script>
</body>
</html>
|
|
|
|
|
hi
i just wanted to know whether u got a solution for your question because i am facing the same problem now but still did not get any solution for it....i need to use javascript to validate a textbox placed in content page so can u plz help me in this issue....i am not able to get the id of the textbox....
K.Gayathri
|
|
|
|
|
Hi all,
I'm trying to parse a web page that shows dinamically some data (is a web game page) that is not contained in the code behind the page (the one that I access using the Chrome developers tools, for example).
I see that I can show this data even detaching my pc from the network, simply selecting an item in the combobox, but the content appears in the page source only when the selected combobox item is changed.
Anyone can suggest me where I can find the hidden data or source code?
Thank you
Leo
|
|
|
|
|
If you are viewing the page with Chrome you can right-click on the item and select Inspect element to see how the item is presented.
|
|
|
|
|
I know this. What I'm looking for is the data that is in the memory of the browser, downloaded from the web server, but presented when the javascript inside the web page decide to show it.
This kind of data is not visible simply using "Inspect element".
|
|
|
|
|
As far as I am aware, you can examine elements of the HTML DOM tree but I do not know of any method to access the browser's memory.
|
|
|
|
|
In Chrome you can view the values of javascript objects.
After you 'Inspect Element' to load up the Source, look for the javascript objects in the code behind files and then in the Chrome console if you type the object name it will tell you the value. Remember to look at the Scripts tab and you can change between all the referenced javascript source files to inspect them.
If you come across any files that have been minified, you can click the {} (Pretty Print as google call it) button at the bottom and it will make the source more readable.
You can also change the value and also run any JS functions, JQuery against the DOM and all sorts. You can also change attributes and values of the CSS if you are doing testing etc.
|
|
|
|
|
Something else I need to learn
|
|
|
|
|
I thought about that this morning, was considering writing a Beginners guide to Browser debugging article........
|
|
|
|
|
DaveAuld wrote: a Beginners guide to Browser debugging
Which would certainly be well received.
|
|
|
|
|
|
See my comment, and I did vote a 5, but it doesn't show in my message title.
Unrequited desire is character building. OriginalGriff
I'm sitting here giving you a standing ovation - Len Goodman
|
|
|
|
|
That would be super useful.
Somebody in an online forum wrote: INTJs never really joke. They make a point. The joke is just a gift wrapper.
|
|
|
|
|
Ok, i've already started.......... may take some time, trying to get the structure and appropriate content is a challenge!
|
|
|
|
|
|
Ok, this is the right reply
I've written some C# code to access this data using a WebBrowser object.
Are you interested in?
|
|
|
|
|
Good Day All
in my page i have a hyperlink button in a gridview defined like this
<a href="#" onclick="<%# String.Format("return showComment('{0}','{1}')", Replace(Eval("Field1").ToString(),Chr(13),"<BR>"), Replace(Eval("Field2").ToString(),Chr(13),"<BR>") ) %>">
<img src="../../Imgs/comment2.png" />
</a>
and the Function showComment is defined like this
function showComment(CommentPend,CommentCancel)
{
$("#btnclose").unbind();
$("#divPendComment").center();
$("#divPendComment").fadeIn('slow');
$("#txtcomment").val(CommentPend.toString().replace(/^[a-z0-9 ]$/i, ''));
$("#txtcommentCancel").val(CommentCancel.toString().replace(/^[a-z0-9 ]$/i, ''));
$("#btnclose").click(function (e)
{
$("#divPendComment").fadeOut('slow');
e.preventDefault();
});
return false;
}
now as you can see i am trying to get rid of the special characters like the carriage returns but still i get a a javascript error when this link is clicked
Uncaught SyntaxError: Unexpected token ILLEGAL
thanks
Vuyiswa Maseko,
Spoted in Daniweb-- Sorry to rant. I hate websites. They are just wierd. They don't behave like normal code.
C#/VB.NET/ASP.NET/SQL7/2000/2005/2008
http://www.vuyiswamaseko.com
vuyiswa[at]dotnetfunda.com
http://www.Dotnetfunda.com
|
|
|
|
|
It means you've committed a crime. Be prepared for arrest.
The difficult we do right away...
...the impossible takes slightly longer.
|
|
|
|