search
HomeWeb Front-endJS Tutorialwindow.location.reload Refresh usage analysis (go to dialog box)_Basic knowledge

Use window.location.reload; when refreshing, if you submit data, an annoying dialog box will appear!

To solve this problem, you should write like this:

window.location.href=window.location.href; 
window.location.reload;

Similarly, if you want to refresh the parent window, you should write like this:

window.opener.location.href=window.opener.location.href; 
window.opener.location.reload();

This way of writing will eliminate that annoying dialog box!

Introducing the method of refreshing iframe with JS

Option 1: Use the name attribute of iframe to locate

<input type="button" name="Button" value="Button" 
onclick="document.frames(&#39;ifrmname&#39;).location.reload()">

or

<input type="button" name="Button" value="Button" 
onclick="document.all.ifrmname.document.location.reload()">

Solution 2: Use the id attribute of the iframe to locate

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

The ultimate solution: When the src of the iframe is another website address (cross-domain operation)

<input type="button" name="Button" value="Button" 
onclick="window.open(document.all.ifrmname.src,&#39;ifrmname&#39;,&#39;&#39;)">

In the following, IE is used instead of Internet Explorer, and MF is used instead of Mozzila Firefox

1. document.form.item issues
(1) Existing issues:
Existing There are many statements like document.formName.item("itemName") in the code, which cannot be run under MF
(2) Solution:
Use document.formName.elements["elementName"] instead (3) Others
See 2

2. Collection class object problems

(1) Existing problems:
Many collection class objects in the existing code use () when accessing them. IE can Accept, MF cannot.
(2) Solution:
Use [] as the subscript operation instead. For example: document.forms("formName") is changed to document.forms["formName"].
Another example: document.getElementsByName("inputName")(1) changed to document.getElementsByName("inputName")[1]
(3) Others

3. window.event

(1) Existing problems:
Cannot run on MF using window.event
(2) Solution:
MF events can only be used at the scene where the event occurs, and this problem cannot be solved yet. It can be modified like this:
Original code (can run in IE):

<input type="button" name="someButton" value="提交" onclick=""/> 
<script language="javascript"> 
 function gotoSubmit() { 
  alert(window.event); // use window.event 
 } 
</script>
New code (can run in IE and MF):

<input type="button" name="someButton" value="提交" 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 in the new code does not change and is the same as the old code (that is, the gotoSubmit call does not give parameters), it will still only run in IE, but no error will occur. Therefore, the tpl part of this solution is still compatible with the old code.

4. The problem of using the id of the HTML object as the object name

(1) Existing problems
In IE, the ID of the HTML object can be used directly as the variable name of the subordinate object of the document. Not in MF.
(2) Solution
Use getElementById("idName") instead of idName as an object variable.

5. Problems with obtaining objects using idName strings

(1) Existing problems
In IE, you can use eval(idName) to obtain the HTML object with the id of idName, but not in MF. .
(2) Solution
Use getElementById(idName) instead of eval(idName).

6. The problem that the variable name is the same as an HTML object id

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

7. event.x and event.y issues

(1) Existing issues
In IE, the event object has x, y attribute, not available in MF.
(2) Solution
In MF, the equivalent of event.x is event.pageX. But event.pageX is not available in IE.
Therefore, event.clientX is used instead of event.x. This variable also exists in IE.
There are subtle differences between event.clientX and event.pageX (when the entire page has scroll bars), but most of the time they are equivalent.

        如果要完全一样,可以稍麻烦些: 
        mX = event.x ? event.x : event.pageX; 
        然后用 mX 代替 event.x 
    (3)其它 
        event.layerX 在 IE 与 MF 中都有,具体意义有无差别尚未试验。

8. 关于frame 
   (1)现有问题 
         在 IE中 可以用window.testFrame取得该frame,mf中不行 
   (2)解决方法 
         在frame的使用方面mf和ie的最主要的区别是: 
如果在frame标签中书写了以下属性: 
 
那么ie可以通过id或者name访问这个frame对应的window对象 
而mf只可以通过name来访问这个frame对应的window对象 
例如如果上述frame标签写在最上层的window里面的htm里面,那么可以这样访问 
ie: window.top.frameId或者window.top.frameName来访问这个window对象 
mf: 只能这样window.top.frameName来访问这个window对象

另外,在mf和ie中都可以使用window.top.document.getElementById("frameId")来访问frame标签 
并且可以通过window.top.document.getElementById("testFrame").src = 'xx.htm'来切换frame的内容 
也都可以通过window.top.frameName.location = 'xx.htm'来切换frame的内容 
关于frame和window的描述可以参见bbs的‘window与frame'文章 
以及/test/js/test_frame/目录下面的测试 
----adun 2004.12.09修改

9. 在mf中,自己定义的属性必须getAttribute()取得 
10.在mf中没有  parentElement parement.children  而用 
   parentNode parentNode.childNodes 
   childNodes的下标的含义在IE和MF中不同,MF使用DOM规范,childNodes中会插入空白文本节点。 
  一般可以通过node.getElementsByTagName()来回避这个问题。 
   当html中节点缺失时,IE和MF对parentNode的解释不同,例如 
  

<form> 
   <table> 
        <input/> 
   </table> 
   </form>

   MF中input.parentNode的值为form, 而IE中input.parentNode的值为空节点

  MF中节点没有removeNode方法,必须使用如下方法 node.parentNode.removeChild(node)

11.const 问题 
  (1)现有问题: 
     在 IE 中不能使用 const 关键字。如 const constVar = 32; 在IE中这是语法错误。 
  (2)解决方法: 
     不使用 const ,以 var 代替。

12. body 对象 
   MF的body在body标签没有被浏览器完全读入之前就存在,而IE则必须在body完全被读入之后才存在

13. url encoding 
在js中如果书写url就直接写&不要写&例如var url = 'xx.jsp?objectName=xx&objectEvent=xxx'; 
frm.action = url那么很有可能url不会被正常显示以至于参数没有正确的传到服务器 
一般会服务器报错参数没有找到 
当然如果是在tpl中例外,因为tpl中符合xml规范,要求&书写为& 
一般MF无法识别js中的&


14. nodeName 和 tagName 问题 
  (1)现有问题: 
     在MF中,所有节点均有 nodeName 值,但 textNode 没有 tagName 值。在 IE 中,nodeName 的使用好象 
     有问题(具体情况没有测试,但我的IE已经死了好几次)。 
  (2)解决方法: 
     使用 tagName,但应检测其是否为空。

15. 元素属性 
   IE下 input.type属性为只读,但是MF下可以修改


16. document.getElementsByName() 和 document.all[name] 的问题 
  (1)现有问题: 
     在 IE 中,getElementsByName()、document.all[name] 均不能用来取得 div 元素(是否还有其它不能取的元素还不知道)。


1,document.getElementById替代document.all(ie适用) 
2,集合[]替代()(ie适用) 
3,target替代srcElement;parentNode替代parentElement(parentNode ie适用) 
4,node.parentNode.removeChild(node)替代removeNode(this)(ie适用) 
5,有空白文本节点 
6,无outerHTML属性 
7,事件局部变量e替代事件全局变量event 
8,e.button键值有别于event.button,只有3个键值而无组合键值 
9,无ondrag事件 
10,DOMMouseScroll替代onmousewheel;-e.detail替代event.wheelDelta 
11,addEventListener替代attachEvent;removeEventListener替代detachEvent 
12,e.preventDefault()替代event.returnValue=false;e.stopPropagation()替代event.cancelBubble=true 
13,style.top、style.left等严格检查"px"单位(加"px" ie适用) 
14,style="-moz-opacity:0.9"替代style="filter:alpha(opacity=90)";无其它filter 
15,style.cursor="pointer"替代style.cursor="hand"(ie适用) 
16,title替代alt(ie适用) 
17,状态栏默认不可修改,需调整ff设置 
18,内置绘图功能以canvas或者SVG替代vml 
19,代码出错时经常不报错(想来也是ff的无奈之举吧,如果每个ie独有的表达方式换在它里面都报错的话,怕是报都报不过来吧) 
20,对缓存的清理非常不好 
注:标明“ie适用”者为通用性建议写法,未标明者在ie里不适用。

以下所有IE指IE6.0

验证是否是IE浏览器(来之于google js)

var agt=navigator.userAgent.toLowerCase(); 
var is_ie=(agt.indexOf("msie")!=-1 && document.all); 
正式开始

事件委托方法

IE

document.body.onload = inject; //Function inject()在这之前已被实现
firefox
document.body.onload = inject();

有人说标准是:

document.body.onload=new Function(&#39;inject()&#39;);

在firefox无法取得event.srcElement

通过其他方式传递对象

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); 
} 
}

这是来之 http://blog.joycode.com/lostinet/archive/2005/02/27/44999.aspx

在FireFox下编写事件处理函数是很麻烦的事. 
因为FireFox并没有 window.event . 如果要得到 event 对象,就必须要声明时间处理函数的第一个参数为event.

所以为了兼容IE与FireFox,一般的事件处理方法为: 

btn.onclick=handle_btn_click; 
function handle_btn_click(evt) 
{ 
if(evt==null)evt=window.event;//IE 
//处理事件. 
}

对于简单的程序,这不算麻烦.

但对于一些复杂的程序,某写函数根本就不是直接与事件挂钩的.如果要把event传进该参数,那么所有的方法都要把event传来传去..这简直就是噩梦.

下面介绍一个解决这个麻烦事的方法,与原理.

JScript中,函数的调用是有一个 func.caller 这个属性的. 
例如 

function A() 
{ 
B(); 
} 
function B() 
{ 
alert(B.caller); 
}

如果B被A调用,那么B.caller就是A

另外,函数有一个arguments属性. 这个属性可以遍历函数当前执行的参数: 

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 
(arguments的个数与调用方有关,而与函数的参数定义没有任何关系)

根据这两个属性,我们可以得到第一个函数的event对象:

btn.onclick=handle_click; 
function handle_click() 
{ 
showcontent(); 
} 
function showcontent() 
{ 
var evt=SearchEvent(); 
if(evt&&evt.shiftKey)//如果是基于事件的调用,并且shift被按下 
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) // 如果就是event 对象 
return arg0; 
} 
func=func.caller; 
} 
return null; 
}

这个例子使用了SearchEvent来搜索event对象. 其中 'Event' 是 FireFox 的 event.constructor . 
在该例子运行时, 
SearchEvent.caller就是showcontent,但是showcontent.arguments[0]是空.所以 func=func.caller 时,func变为handle_click . 
handle_click 被 FireFox 调用, 虽然没有定义参数,但是被调用时,第一个参数就是event,所以handle_click.arguments[0]就是event !

针对上面的知识,我们可以结合 prototype.__defineGetter__ 来实现 window.event 在 FireFox 下的实现:

下面给出一个简单的代码.. 有兴趣的可以补充

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></html>

firefox与IE(parentElement)的父元素的区别

因为firefox与IE都支持DOM,因此使用obj.parentNode是不错选择.

IE 
obj.parentElement 
firefox 
obj.parentNode

asp.net中UniqueID和clientID的区别

要使用document.getElementById 方法,则使用控件的时候要这样来作

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

调用Select元素的区别

移出一个选择项

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

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

增加选择项:

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

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

The above is the content of window.location.reload refresh usage analysis (go to dialog box)_basic knowledge. For more related content, please pay attention to the PHP Chinese website (www.php.cn)!


Statement
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
location.reload()用法机制location.reload()用法机制Jun 25, 2023 pm 05:43 PM

location.reload()用法机制:1、无参数调用,浏览器会重新加载当前页面;2、参数为true,会强制浏览器使用缓存之外的新版本加载页面;3、参数为false或省略参数,会重新加载页面,但将优先从缓存加载。

location.reload用法详解location.reload用法详解Dec 06, 2023 pm 03:08 PM

location.reload用于重新加载当前文档。这个方法可以用来刷新页面或重新加载当前页面,以获取最新的内容。

window10平板电脑系统安装的详细图文教程window10平板电脑系统安装的详细图文教程Jul 14, 2023 am 09:33 AM

平板电脑是目前很多年轻人都非常喜欢的电脑。最近就有不少小伙伴想要了解window10平板电脑系统怎么安装,那么今天小编就来跟大家分享一下一个操作十分简单的一键安装win10的方法。下面就让我们一起来看看吧!window10平板电脑系统安装的详细图文教程:1、我们搜索下载小白一键重装系统软件,选择下载安装win10操作系统,点击安装此系统。2、等待小白下载以及部署环境。3、等待部署完成后点击立即重启即可。4、选择进入小白pe系统。5、进入pe系统后弹出装机工具帮助我们自动重装系统,我们无需任何操作

window10重装win7系统教程window10重装win7系统教程Jul 08, 2023 pm 05:45 PM

很多小伙伴使用win10系统不习惯想装回win7系统,却不知道如何下手,下面小编就把这个简单的方法教给大家吧,不会电脑重装windows7的小伙伴不要错过了。1、首先我们打开电脑浏览器搜索魔法猪一键重装系统官网,下载下来并打开它。2、下载好之后我们打开它,点击在线重装即可。3、接下来我们耐心等待它安装完后就可以了。4、安装完成,接下来我们需要点击立即重启电脑。5、重启完电脑之后我们还需要返回主界面继续完成安装,接下来我们的安装就完成了。以上就是window10重装win7系统的步骤了,希望对大家

如何实现Disk Pulse Eneterprise Window应用程序的漏洞分析如何实现Disk Pulse Eneterprise Window应用程序的漏洞分析May 18, 2023 pm 03:04 PM

一、漏洞简介DiskPulseEneterprise是一款监视磁盘变化的软件,它可以通过一个管理端口9120或者web管理窗口80对软件进行连接管理,从而监视磁盘的变化情况。在DiskPulseEneterprise中有一个动态链接库libspp.dll,其中有一些负责HTTP操作的函数,问题就出现在这个动态链接库中,在处理后数据时,由于对于后数据没有进行严格的长度控制,导致在执行获取后数据时向无效内存拷贝数据造成缓冲区溢出,触发SEH异常行为处理,最后控制EIP,执行任意代码。软件下载链接:h

Window蠕虫病毒怎么解决Window蠕虫病毒怎么解决May 17, 2023 pm 07:22 PM

0x00前言蠕虫病毒是一种十分古老的计算机病毒,它是一种自包含的程序(或是一套程序),通常通过网络途径传播,每入侵到一台新的计算机,它就在这台计算机上复制自己,并自动执行它自身的程序。常见的蠕虫病毒:熊猫烧香病毒、冲击波/震荡波病毒、conficker病毒等。0x01应急场景某天早上,管理员在出口防火墙发现内网服务器不断向境外IP发起主动连接,内网环境,无法连通外网,无图脑补。0x02事件分析在出口防火墙看到的服务器内网IP,首先将中病毒的主机从内网断开,然后登录该服务器,打开D盾_web查杀查

window10共享计算机用户名和密码的修改方法window10共享计算机用户名和密码的修改方法Jul 21, 2023 am 11:05 AM

在工作中,我们经常使用计算机分享功能。近日有不少小伙伴问小编window10共享电脑的用户名和密码是如何修改的,那么今天小编就和大家分享修改window10共享电脑的用户名和密码。没有什么比这更重要的了,让我们一起学习它吧!如何修改window10共享电脑用户名和密码:1.按下win键+r键,输入control单击确定。2.点击用户帐户。3.点击凭据管理员。4.点击Windows凭据。5.共享中的凭证就是这个凭证,点击编辑即可进行更改。以下是如何修改window10共享计算机用户名和密码的方法。

电脑出现Window10此版本将要关闭该怎么办?电脑出现Window10此版本将要关闭该怎么办?Jul 08, 2023 pm 08:02 PM

电脑出现Window10此版本将要关闭该怎么办?近期有很多朋友在应用Win10系统软件的历程中,电脑上忽然跳出来:将要重新启动你的Windows10版本将要停止服务项目的提醒,实际上它是Win10现阶段版本将要停止微软系统软件的新通告中的服务项目,那麼面临这样的事情该怎么办呢?下边小编就来提醒大伙儿电脑出现Window10此版本将要关闭解决方案。电脑出现Window10此版本将要关闭解决方案方式一:选择升级1、点一下“菜单栏”标志,选择“设置”进到;2、设置界面中立即选定“升级和安全性”进到;3

See all articles

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks agoBy尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

Safe Exam Browser

Safe Exam Browser

Safe Exam Browser is a secure browser environment for taking online exams securely. This software turns any computer into a secure workstation. It controls access to any utility and prevents students from using unauthorized resources.

SublimeText3 English version

SublimeText3 English version

Recommended: Win version, supports code prompts!

ZendStudio 13.5.1 Mac

ZendStudio 13.5.1 Mac

Powerful PHP integrated development environment