Refresh problem in Firefox

2019-02-15 23:20发布

问题:

In my asp page there is one textbox name "ProductName"

if i write any thing in that textbox and refresh that page , textbox is not clear in firefox. But i open this same page in Internet explore and write any thing in textbox and refresh the page, my textbox comes clear

why textbox not comes clear in FireFox?

This is the html code

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=windows-1252">
<title>New Page 1</title>
</head>
<body>
<input type="text" id="ProductName" name="ProductName" style="width:235; height:20" value="">
</body>
</html>

回答1:

This is a feature of Firefox (one I'm quite fond of). There's nothing you can do about it on the server-side.

EDIT:

The longer version: There is something you can do about, but it's very messy. Basically, the way Firefox implements this is it refills in form elements with the same name when the user hits the refresh button.

The workaround is to change the name attribute on your HTML form elements every time the page loads. How you keep track of what you change them too is left to your discretion, but let me just say that as a Firefox user myself, having a website do this would annoy me no end.



回答2:

"Actually firefox is stupid that way." - yes it is.

Another way would be to set autocomplete="off" on the input



回答3:

You can add the autocomplete="off" attribute to the input as shown below and it should fix the issue.

<input type="text" id="ProductName" name="ProductName" style="width:235; height:20" value="" autocomplete="off">


回答4:

Firefox isn't stupid that way. That's appropriate behavior because presumably the div your fading in occurs on an event e.g. onclick, onchange, etc. And since that event isn't triggered on refresh firefox has no reason to show your div. It's your responsibility to write the js necessary to trigger events onload or when document is ready.

Back to topic: a simple solution is to set the autocomplete attribute of your form to 'off'

That's it.



回答5:

Actually firefox is stupid that way. Let's say you have a checkbox and when the user clicks to activate that checkbox there is a div that should fade in. The problem here is that if you refresh the page your checkbox will remain active but your div will be hidden. They(firefox) did not think it all the way through and that is .. well stupid. Because of that you have to resort to js workarounds which (I'm not quite fond of).

I do agree that you need to have, at some poin, the same value inside some input, like when you submit a page, there is an error and you need to redirect the user back to the page containing the form. Then yeah!, ok!, you need the values... but to keep the values on refresh , well that s just stupid.

What user enters his details and then just thinks "hm I'll just press f5 now see what happens". If that's the kind of user 'roaming round' your site, please shut it down it's infested with stupidity

Ok so now that that is out of the way.

"change the name attribute on your HTML form elements every time the page loads" this is a bad idea don`t do this...

instead you can use a js function that simply gets the input and sets the value to ""

onpageload:
document.getElementById('inp1').value = '';
document.getElementById('inp2').value = '';
document.getElementById('inp3').value = '';

and so on and so forth. P.S. this is just an example, it's your job to see, what fits for you (be it jquery, prot or whatever); to see if you use a for loop or not; etc



回答6:

HTMLFormElement instances inherit a reset method.

It can be used to clear all forms to its default values:

for(var i=0; i<document.forms.length; ++i)
    document.forms[i].reset();


回答7:

for this problem add

autocomplete="off"

attr to input tag for example:

<input type="text" autocomplete="off" id="ProductName" name="ProductName" style="width:235; height:20" value="">


回答8:

You can use Ctrl+Shift+R command to force reload (not from cache) (see Page Navigation Shortcuts on http://www-archive.mozilla.org/docs/end-user/moz_shortcuts.html)