Window. location. reload refresh use analysis (go to the dialog box), window. location refresh

Source: Internet
Author: User

Window. location. reload refresh use analysis (go to the dialog box), window. location refresh

When you use window. location. reload; to refresh, if you submit data, an annoying dialog box is displayed!

To solve this problem, write as follows:
Window. location. href = window. location. href;
Window. location. reload;
Similarly, to refresh the parent window, you should write as follows:
Window. opener. location. href = window. opener. location. href;
Window. opener. location. reload ();
In this way, there will be no such annoying dialog box!

This article introduces how to refresh iframe in JS.
<Iframe src = "1.htm" name =" ifrmname "id =" ifrmid "> </iframe>

Solution 1: use the name attribute of iframe to locate

<Input type = "button" name = "Button" value = "Button"
Onclick = "document. frames ('ifrmname'). location. reload ()">

Or

<Input type = "button" name = "Button" value = "Button"
Onclick = "document.all.ifrmname.doc ument. location. reload ()">

Solution 2: Use the id attribute of iframe to locate

<Input type = "button" name = "Button" value = "Button"
Onclick = "ifrmid. window. location. reload ()">

Ultimate Solution: When the src of iframe is another website address (during cross-origin operations)

<Input type = "button" name = "Button" value = "Button"
Onclick = "window. open (document. all. ifrmname. src, 'ifrmname','') ">

Internet Explorer is replaced by IE and Mozzila Firefox is replaced by MF.

1. document. form. item Problems
(1) existing problems:
Many statements such as document. formName. item ("itemName") exist in the existing code and cannot be run in MF.
(2) solution:
Use document. formName. elements ["elementName"]
(3) Others
See 2

2. Collection class Object Problems
(1) existing problems:
In the existing Code, many collection class objects are used (), which is acceptable to IE and cannot be used by MF.
(2) solution:
Use [] as the subscript operation. For example, change document. forms ("formName") to document. forms ["formName"].
For example, change document. getElementsByName ("inputName") (1) to document. getElementsByName ("inputName") [1]
(3) Others

3. window. event
(1) existing problems:
Window. event cannot be run on MF.
(2) solution:
MF events can only be used in the event. This problem cannot be solved. This can be changed as follows:
Original code (can be run in IE ):

<Input type = "button" name = "someButton" value = "Submit" onclick = ""/> <script language = "javascript"> function gotoSubmit () {alert (window. event); // use window. event} </script>

New Code (run in IE and MF ):

<Input type = "button" name = "someButton" value = "Submit" onclick = ""/> <script language = "javascript"> function gotoSubmit (evt) {evt = evt? Evt: (window. event? Window. event: null); alert (evt); // use evt} </script>

In addition, if the first line of the new Code is not modified, it is the same as the old code (that is, the gotoSubmit call does not provide a parameter), it can only be run in IE, but no error occurs. Therefore, the tpl part of this solution is still compatible with the old code.

4. Question about the id of an HTML object as the object name
(1) Existing Problems
In IE, the ID of the HTML object can be directly used as the variable name of the subordinate object of the document. It cannot be in MF.
(2) Solution
Use getElementById ("idName") instead of idName as the object variable.

5. The problem of getting an object using the idName string
(1) Existing Problems
In IE, eval (idName) can be used to obtain the HTML object with id as idName, which cannot be used in MF.
(2) Solution
Use getElementById (idName) instead of eval (idName ).

6. The variable name is the same as the id of an HTML object.
(1) Existing Problems
In MF, because the Object id is not the name of the HTML object, you can use the same variable name as the HTML Object id, which cannot be used in IE.
(2) Solution
When declaring variables, add var to avoid ambiguity, so that it can run normally in IE.
In addition, it is best not to take the same variable name as the HTML Object id to reduce errors.
(3) Others
See question 4

7. event. x and event. y
(1) Existing Problems
In IE, the event object has the x and y attributes, and MF does not.
(2) Solution
In MF, event. x is equivalent to event. pageX. But event. pageX IE does not.
Therefore, event. clientX is used instead of event. x. This variable is also available in IE.
Event. clientX is slightly different from event. pageX (when the page has a scroll bar), but most of the time it is equivalent.

If it is the same, it may be a little troublesome:
MX = event. x? Event. x: event. pageX;
Use mX instead of event. x
(3) Others
Event. layerX is available in both IE and MF. There is no difference in the specific significance of this function.

8. About frame
(1) Existing Problems
In IE, the frame can be obtained using window. testFrame, but not in mf.
(2) Solution
The main difference between mf and ie in frame usage is:
If the following attributes are written in the frame tag:
<Frame src = "xx.htm" id = "frameId" name = "frameName"/>
Then ie can access the window object corresponding to this frame through id or name.
However, mf can only access the window object corresponding to this frame through name.
For example, if the above frame label is written in the htm in the top window, you can access
Ie: window. top. frameId or window. top. frameName to access this window object
Mf: only window. top. frameName can access this window object.

In addition, both mfand iecan use javasdesktop.doc ument. getElementById ("frameId") to access the frame tag.
In addition, you can switch the frame content through the parameter top.doc ument. getElementById ("testFrame"). src = 'xx.htm '.
You can also switch the frame content through window. top. frameName. location = 'xx.htm '.
For details about frame and window, see the 'window and framework' article in bbs.
And the tests under the/test/js/test_frame/directory
---- Adun 2004.12.09 Modification

9. In mf, attributes defined by myself must be obtained by getAttribute ().
10. If there is no parentElement parement. children in mf, use
ParentNode. childNodes
ChildNodes has different meanings in IE and MF. MF uses DOM specifications, and blank text nodes are inserted in childNodes.
You can avoid this problem by using node. getElementsByTagName.
When a node in html is missing, IE and MF have different interpretations of parentNode, for example
<Form>
<Table>
<Input/>
</Table>
</Form>
In MF, the value of input. parentNode is form, while that of input. parentNode in IE is empty.

The node in MF does not have the removeNode method. You must use the following method: node. parentNode. removeChild (node)

11. const Problems
(1) existing problems:
You cannot use the const keyword in IE. For example, const constVar = 32; in IE, This Is A syntax error.
(2) solution:
Use var instead of const.

12. body object
The MF body exists before the body tag is fully read by the browser, While IE exists only after the body is fully read.

13. url encoding
In js, if the url is written, write directly & do not write & for example, var url = 'xx. jsp? ObjectName = xx & objectEvent = XXX ';
Frm. action = url, so it is very likely that the url will not be properly displayed, so that the parameter is not correctly transmitted to the server.
Generally, the server reports that the error parameter is not found.
Of course, if it is an exception in tpl, because tpl complies with the xml specification, the requirements are as follows &
Generally, MF cannot recognize &


14. nodeName and tagName Problems
(1) existing problems:
In MF, all nodes have a nodeName value, but textNode does not have a tagName value. In IE, nodeName usage seems to be
There is a problem (the test is not performed, but my IE has been killed several times ).
(2) solution:
Use tagName, but check whether it is empty.

15. Element attributes
The input. type attribute in IE is read-only, but can be modified in MF.


16. document. getElementsByName () and document. all [name] Problems
(1) existing problems:
In IE, neither getElementsByName () nor document. all [name] can be used to obtain the div element (whether there are other elements that cannot be retrieved is unknown ).


1. Replacing document. all with document. getElementById (applicable to ie)
2. Set [] substitution () (applicable to ie)
3. target replaces srcElement; parentNode replaces parentElement (applicable to parentNode ie)
4. node. parentNode. removeChild (node) replaces removeNode (this) (for ie)
5. blank text nodes
6. No outerHTML attribute
7. The event local variable e replaces the event global variable event
8. The key value of e. button is different from that of event. button. There are only three key values, but no key combination.
9. No ondrag event
10. DOMMouseScroll replaces onmousewheel;-e. detail replaces event. wheelDelta.
11. addEventListener replaces attachEvent; removeEventListener replaces detachEvent
12, e. preventDefault () replace event. returnValue = false; e. stopPropagation () replace event. cancelBubble = true
13. Strictly check "px" units such as style. top and style. left (applicable to "px" ie)
14, style = "-moz-opacity: 0.9" alternative style = "filter: alpha (opacity = 90)"; no other Filters
15. style. cursor = "pointer" to replace style. cursor = "hand" (for ie)
16. Replacing alt with title (applicable to ie)
17. The status bar cannot be modified by default. You need to adjust the ff setting.
18. The built-in drawing function replaces vml with canvas or SVG
19. Do not report errors frequently when code errors occur. (ff is also helpless. If every unique expression of ie reports an error in it, I am afraid it will fail to be reported)
20. The cache is very poor.
Note: It is recommended to indicate that "ie applies" for general purposes, but not for ie.

All of the following Internet Explorer

Verify whether it is an Internet browser (for google js)

Var agt = navigator. userAgent. toLowerCase ();
Var is_ie = (agt. indexOf ("msie ")! =-1 & document. all );
Official start

Event Delegate Method

IE

Document. body. onload = inject; // Function inject () has been implemented before this

Firefox

Document. body. onload = inject ();

Some people say the standard is:

Document. body. onload = new Function ('inject ()');


Event. srcElement cannot be obtained in firefox

Passing objects in other ways

if(isIE) thistable.attachEvent("onmousedown",OnClickChangeTdBackColor); //thistable.onmousedown=OnClickChangeTdBackColor; else//deal firefox { for(var i=0;i<thistable.rows.length;i++) { var rowObj = thistable.rows[i]; for( var j=0;j<rowObj.cells.length;j++) { var cellObj = rowObj.cells[j]; cellObj.setAttribute("onmousedown","OnClickChangeTdBackColor(this)"); } //alert(rowObj.cells[0].tagName); } } 

This is the coming http://blog.joycode.com/lostinet/archive/2005/02/27/44999.aspx

Writing event processing functions in FireFox is troublesome.
Because FireFox does not have window. event. To get the event object, you must declare the first parameter of the time processing function as event.

To be compatible with IE and FireFox, the general event handling method is:
Btn. onclick = handle_btn_click;
Function handle_btn_click (evt)
{
If (evt = null) evt = window. event; // IE
// Process the event.
}
This is not a hassle for simple programs.

However, for some complex programs, a write function is not directly linked to the event. if you want to pass the event to this parameter, all methods must pass the event .. this is a nightmare.

The following describes how to solve this problem and how it works.

In JScript, a function call has the func. caller attribute.
For example
Function ()
{
B ();
}
Function B ()
{
Alert (B. caller );
}
If B is called by A, B. caller is

In addition, the function has an arguments attribute, which can traverse the parameters currently executed by the function:
Function myalert ()
{
Var arr = [];
For (var I = 0; I
Arr [I] = myalert. arguments [I];
Alert (arr. join ("-"));
}
Alert ("hello", "world", 1, 2, 3)
Hello-world-1-2-3
(The number of arguments is related to the caller, but not to the parameter definition of the function)

Based on these two attributes, we can get the event object of the first function:

Btn. onclick = handle_click; function handle_click () {showcontent ();} function showcontent () {var evt = SearchEvent (); if (evt & evt. shiftKey) // if it is an event-based call and shift is pressed by window. open (global_helpurl); else location. href = global_helpurl;} function SearchEvent () {func = SearchEvent. caller; while (func! = Null) {var arg0 = func. arguments [0]; if (arg0) {if (arg0.constructor = Event) // return arg0;} func = func. caller;} return null ;}

In this example, SearchEvent is used to search for event objects. 'event' is the FireFox Event. constructor.
In this example,
SearchEvent. caller is showcontent, but showcontent. arguments [0] is empty. So when func = func. caller, func becomes handle_click.
Handle_click is called by FireFox. Although no parameters are defined, the first parameter is event when called. Therefore, handle_click.arguments [0] is event!

Based on the above knowledge, we can combine prototype. _ defineGetter _ to implement window. event in FireFox:

A simple code is provided below. If you are interested, you can add

if(window.addEventListener) { FixPrototypeForGecko(); } function FixPrototypeForGecko() { HTMLElement.prototype.__defineGetter__("runtimeStyle",element_prototype_get_runtimeStyle); window.constructor.prototype.__defineGetter__("event",window_prototype_get_event); Event.prototype.__defineGetter__("srcElement",event_prototype_get_srcElement); } function element_prototype_get_runtimeStyle() { //return style instead... return this.style; } function window_prototype_get_event() { return SearchEvent(); } function event_prototype_get_srcElement() { return this.target; } function SearchEvent() { //IE if(document.all) return window.event; func=SearchEvent.caller; while(func!=null) { var arg0=func.arguments[0]; if(arg0) { if(arg0.constructor==Event) return arg0; } func=func.caller; } return null; } </body>

The difference between firefox and IE (parentElement) parent Elements

Because firefox and IE support DOM, using obj. parentNode is a good choice.

IE
Obj. parentElement
Firefox
Obj. parentNode

Differences between UniqueID and clientID in asp.net

To use the document. getElementById method, use the control as follows:

"Javascript: OnSelectSubCatalog (\" "+ subCatalog_drp.ClientID +" \ "," + catalogIDX + "," + catID. ToString () + ")";

Differences between calling Select elements

Remove a selected item

--------------------------------------------------------------------------------

IE: sel. options. remove (sel. selectedIndex );
Firefox:

Add a selection item:

--------------------------------------------------------------------------------

IE: subCatalog. add (new Option (text, value ));

Firefox:

Var opnObj = document. createElement ("OPTION ");
// OpnObj. id = optionID;
OpnObj. value = value;
OpnObj. text = text;
SubCatalog. appendChild (opnObj );

Cursor: hand VS cursor: pointer

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.