【IT专家】window.open打开弹出而不是窗口
【IT专家】window.open不是函数错误,请帮忙。我到处都看,不明白

本文由我司收集整编,推荐下载,如有疑问,请与我司联系window.open不是函数错误,请帮忙。
我到处都看,不明白window.open不是函数错误,请帮忙。
我到处都看,不明白[英]window.open is not a function error, Please help. I have looked everywhere, cant understand 0 It appears that you have assigned some value to window.open someplace in your script. Look for code upstream that may have done this accidentally. 您似乎已在window.open中为脚本中的某个位置分配了一些值。
查找可能意外执行此操作的上游代码。
This reproduces your problem: 这再现了你的问题: window.open = “no such function”;window.open(‘/index/11’,’upp’,’scrollbars=1,top=0,left=0,resizable=1,width=68 0,height=350’); https://jsfiddle/9aktx53g/ 2 If you have overwritten the window property you can ether call open on its own or get the global context using the following trick (doesn’t work for strict mode): 如果你已经覆盖了window属性,你可以自己打开以及使用以下技巧获取全局上下文(对于严格模式不起作用): new Function(‘return this;’)().open(‘/index/11’,’upp’,’scrollbars=1,top=0,left=0,resizable=1,width=680,height=3 50’); You can also refer to window as self or (parent and top if you are not in a frame): 您也可以将窗口称为self或(如果您不在框架中,则为parent和top): console.log(window === self); // trueconsole.log(window === parent); // true if no framesconsole.log(window === top); // true if no framestips:感谢大家的阅读,本文由我司收集整编。
window.open新打开窗口与新开标签页

wind ow.open新打开窗⼝与新开标签页最近在使⽤window.open时忽略了⼀个细节问题:window.open新打开⼀个窗⼝,但是有时却是新打开⼀个窗⼝有时打开⼀个新标签页。
虽然对⼀般的需求来说,这个两种情况都⽆所谓,但是对于那种有强烈区分的需求来说还是要注意的。
那么怎么会出现这种不同的打开情况呢,这要从window.open⽅法的⽤法和不同浏览器来区分。
1、wind ow.op e n的⽤法容易忽视的细节window.open⽅法有三个参数: window.open(url, [name], [configuration])其中:url, 为要新打开页⾯的urlname,为新打开窗⼝的名字,可以通过此名字获取该窗⼝对象configuration,为新打开窗⼝的⼀些配置项,⽐如是否有菜单栏、滚动条、长⾼等等信息例如,新打开⼀个没有菜单栏、标题栏、⼯具栏,但是有滚动条、状态栏、地址栏且可伸缩窗⼝的⽅法调⽤如下:window.open("index.h tml","newWindow","menubar=0,scrollbars=1, resizable=1,status=1,titlebar=0,toolbar=0,location=1");以上只是简要描述了window.open的⽅法,但是这个⽅法容易忽略的地⽅就是:新打开窗⼝名字可以是⾃定义的值,此外还可以是以下⼏个值,与超链接a的target属性值相同窗⼝name值描述_blank默认的,在新窗⼝打开链接的url_self在当前窗⼝打开链接url_parent在⽗窗⼝打开链接url_top在顶级窗⼝打开urlframename在指定的框架中打开链接url2、wind ow.op e n打开新窗⼝还是打开新标签页调⽤window.open是打开新窗⼝,还是打开新标签页,其实没有什么要紧关系,但是有些需求在这⽅⾯有很强的意愿时,那就得区分⼀下了。
window.open 用法

"window.open()" 方法用于打开一个新的浏览器窗口或查找一个已命名的窗口。
它有四个参数:
1. "url":要打开的资源的URL 或路径。
可以是同域的,也可以是跨域的。
2. "name":新窗口的名称,可以是任何字符串。
3. "specs":一个可选的字符串,用于指定新窗口的特性,例如大小、位置、工具栏等。
可以通过逗号或分号分隔不同的特性。
4. "replace":一个可选的布尔值,指示是否要替换当前窗口的内容。
如果设置为"true",则当前窗口的内容将被替换为新的URL,如果设置为"false",则新的URL 将在新的窗口或选项卡中打开。
下面是一个示例,展示如何使用"window.open()" 方法打开一个新的窗口:
window.open('localhost', 'Example', 'width=500,height=500');
这个示例将打开一个名为"Example" 的新窗口,该窗口的大小为500x500 像素,并加载localhost的内容。
window.opener用法

window.opener 的用法在一般的用法中,只是用来解决关闭窗口时不提示弹出窗口,而对它更深层的了解一般比较少。
其实 window.opener是指调用window.open方法的窗口。
在工作中主要是用来解决部分提交的。
这种跨页操作对工作是非常有帮助的。
如果你在主窗口打开了一个页面,并且希望主窗口刷新就用这个,打开页面的window.opener就相当于主窗口的window。
主窗口的刷新你可以用window.opener.location.reload();如果你用虚拟的目录:如struts的*.do会提示你重试你可以改成这样 window.opener.yourformname.submit()就好了2〉在应用中有这样一个情况,在A窗口中打开B窗口,在B窗口中操作完以后关闭B窗口,同时自动刷新A窗口function closeWin(){hasClosed = true;window.opener.location="javascript:reloadPage();";window.close();}function window.onbeforeunload(){if(!hasClosed){window.opener.location="javascript:reloadPage();";}}</script>上面的代码在关闭B窗口的时候会提示错误,说缺少Object,正确的代码如下:function closeWin(){hasClosed = true;window.opener.location="javascript:reloadPage();";window.opener=null;window.close();}function window.onbeforeunload(){if(!hasClosed){//如果已经执行了closeWin方法,则不执行本方法window.opener.location="javascript:reloadPage();";}}</script>reloadPage方法如下:function reloadPage() {history.go(0);document.execCommand("refresh")document.location = document.location;document.location.reload();}PS:由于需要支持正常关闭和强制关闭窗口时能捕捉到事件,用了全局变量hasClosed ==============================================补充,在父窗口是frame的时候在刷新父窗口的时候会出现问题:The page cannot be refreshed without resending the information.后修改如下:window.opener.parent.document.frames.item('mainFrame').location.href = window.open er.location.href;不需要执行自带的reload()方法,注意,不要再画蛇添足加上这一句:window.opener.parent.document.frames.item('mainFrame').location.reload();============================================================= ===========================最后,为了同时支持刷新普通父窗口和frame父窗口,代码如下:function closeWin() {hasClosed = true;<%if(null != frame){%>window.opener.parent.document.frames.item('mainFrame').location.href = window. opener.location.href;<%}else{%>window.opener.location = "javascript:reloadPage();";<%}%>//window.opener.top.mainFrame.location="javascript:reloadPage();";//self.opener.frames.mainFrame.location.reload(true);window.opener = null;window.close();}function window.onbeforeunload(){if (!hasClosed) {<%if(null != frame){%>window.opener.parent.document.frames.item('mainFrame').location.href = windo w.opener.location.href;<%}else{%>window.opener.location = "javascript:reloadPage();";<%}%>window.opener = null;}}。
window.open打开新窗口后,原窗口显示[object]解决方法
![window.open打开新窗口后,原窗口显示[object]解决方法](https://img.taocdn.com/s3/m/efb91160af1ffc4ffe47ac89.png)
函数原型:window.open(URL,name,param)
URL:要弹出的新的网页
name:弹出新网页的名字(不是文件名),可为空。
param:
height:窗口的像素高度。为与先前版本相兼容,这个参数仍然存在。但在JavaScript1.2中被innerHeight取代。
解决方法:
1.<a href="javascript:window.open('about:blank','_blank');void(0);">ddd</a>只需要在href中加入void(0);即可
2.<a href="#" onclick="window.open('about:blank','_blank')">ddd</a>
width:窗口的像素宽度。为与先前版本相兼容,这个参数仍然存在。但在JavaScript1.2中被innerWidth取代。
location: 是否显示地址栏
menubar:是否显示菜单栏
titlebar: 是否显示标题栏
toolbar: 是否显示工具栏
resizable:指明窗口大小是否可以调整
top=0 窗口距离屏幕上方的象素值
left=0 窗口距离屏幕左侧的象素值
status: 是否显示状态栏
window.open打开新窗口

window.open打开新窗⼝⾸先说我这⼈⽐较懒,懒得敲键盘,这些东西都是不知道我什么时间从⽹上考过来的,也是我学习C#的过程中遇到的⼀些问题,我把我找的解决办法写在下⾯,这些东西对于初学者还是有⼀定的帮助的。
1,基本描述1.1 ⽅法签名:oNewWindow = window.open( sURL , sName , sFeatures, bReplace)通过⽅法签名可以看出,window.open在打开⼀个窗⼝(其url为sURL)后,将返回⼀个代表该窗⼝对象的⼀个变量oNewWindow,如果打开不成功,则oNewWindow的值为null。
同时为了对打开的窗⼝预先做⼀些控制,提供了其他⼀些参数(sName、sFeatures、bReplace)可供选择配置,下⾯将具体说明每个参数的含义1.2 各参数的含义* oNewWindow:被打开的窗⼝的对象* sUrl:被打开窗⼝的url* sName:在哪个窗⼝打开新的url链接,例如可以为_blank(新窗⼝)、_top(最外层窗⼝)等等* sFeatures:对窗⼝的⼀些控制属性o fullscreen:是否为全屏模式(相当于F11的效果),可取值:yes/1、no/0o directories:是否带有⽬录按钮(例如收藏夹中的’链接’⽬录),可取值同上o location:是否带有地址栏,可取值同上o channelmode:是否为影院模式,可取值同上o menubar:是否带有菜单条,可取值同上o resizable:是否可以改变窗⼝的尺⼨,可取值同上o scrollbars:是否带有滚动条,可取值同上o status:是否带有状态栏,可取值同上o titlebar:是否带有标题栏,可取值同上o toolbar:是否带有快捷⼯具栏,可取值同上o height:窗⼝⾼度o width:窗⼝宽度o top:距屏幕上边缘的距离o left:距屏幕左边缘的距离* bReplace:如果在同⼀窗⼝打开新窗⼝,该值⽤于指定是否在history中替换原窗⼝的url链接,可取值:true/false2,基本使⽤* 在⼀个新窗⼝中打开某个链接link(/myoa/admin/manage.jsp)window.open ( “/myoa/admin/manage.jsp” ) ;或者window.open ( “/myoa/admin/manage.jsp” , “_blank” ) ;注意:这样的话,每次执⾏都会打开⼀个新窗⼝,即使上次打开的新窗⼝未关闭,仍然会弹出新的* 在指定的某个窗⼝中打开某个链接link(/myoa/admin/manage.jsp)window.open ( “/myoa/admin/manage.jsp” , “myWiddown” ) ; //myWindow即为窗⼝的名称注意:如果myWindow窗⼝不存在,那么将会新弹出⼀个窗⼝,并将新窗⼝命名为myWindow,只要该窗⼝不关闭,那么以后执⾏该open,弹出窗⼝均为这个已经存在的myWindow另外,有⼀些窗⼝名称已经被浏览器使⽤,具有特殊的含义,例如:_blank、_top、_parent、_self等* 打开⼀个新窗⼝,要求窗⼝⾼度300px、宽度500px、不带滚动条、不带地址栏(/myoa/admin/manage.jsp)window.open ( “/myoa/admin/manage.jsp” , “_blank” , “height=300,width=500,scrollbars=no,location=no” ) ;注意:sFeatures这些参数之间是⽤逗号分隔的,⽽在window.showModalDialog中,是⽤分号进⾏分隔的,⼀定要注意!3,⾼级部分* 原窗⼝与弹出窗⼝之间的对象定位o 概述:弹出窗⼝是我们在页⾯编程中经常使⽤的⼀种⽅式,从互动⾓度分析,弹出窗⼝主要有两种类型,⼀种是信息显⽰窗⼝,例如⼈员信息、⽂章信息等等;另外⼀种是继续处理窗⼝,例如有些项⽬中,新建⽂章就是弹出窗⼝来完成的。
打开一个新窗口 子窗口中调用父窗口的方法
主要实现父子关系的页面window.opener 是window.open 打开的子页面调用父页面对象a.html<html><head><title>主页面</title><script type="text/javascript">/** 为测试IFrame子窗口调用父窗口的全局变量而添加的测试变量*/var parentVairous = "为测试IFrame子窗口调用父窗口的全局变量而添加的测试变量";/*** 因为不同于IFrame(IFrame有id,window.open()与IFrame的父子窗口的模式不同), * 所以当是通过window.open()方法打开一个新窗口使, 必须有一个新窗口的对象* 当然必须先让子窗口弹出来, 才能调用子窗口中的变量, 否则抛出异常*/var OpenWindow;function openSubWin(){OpenWindow = window.open('b.html', 'newwindow', 'height=1024, width=1300, top=0, left=0, toolbar=no, menubar=yes, scrollbars=yes,resizable=yes,location=no, status=no');}function parentInvokeChild(){if(OpenWindow)//当然必须先让子窗口弹出来, 才能调用子窗口中的变量, 否则抛出异常{alert(OpenWindow.iFrameVair);}}</script></head><body><form name="form1" id="form1"><input type="text" name="username" id="username"/><input type="button" value="弹出子页面" onclick = "openSubWin()"><input type="button" value="测试调用弹出窗口中的全局变量" onclick = "parentInvokeChild()"></form></body></html>b.html<html><head><title>子页面</title><script type="text/javascript">/** 为测试父窗体调用IFrame子窗体的全局函数而添加的子窗口全局函数*/var iFrameVair = "测试父窗体调用IFrame子窗体的全局函数";function UpdateParent(){var _parentWin = window.opener;_ername.value = "xxxx" ;}function childInvokeParent(){var parentV airous = window.opener.window.parentVairous;alert(parentVairous);}</script></head><body><form name="form1" id="form1"><p> </p><p align="center"><input type="button"onclick = "UpdateParent();"name="button"id="button"value="更新主页面的UserName内容"><input type = "button"name = "button2"id = "button2"value = "测试IFrame子窗口调用父窗口的全局变量"onclick = "childInvokeParent();"/></p><p> </p></form></body>。
window.open()弹出窗口参数说明及居中设置
window.open()弹出窗⼝参数说明及居中设置window.open()可以弹出⼀个新的窗⼝,并且通过参数控制窗⼝的各项属性。
最基本的弹出窗⼝代码window.open('/');window.open()各参数详解⽰例代码:window.open('/', 'newwindow', 'height=100, width=400, top=0, left=0, toolbar=no, menubar=no, scrollbars=no, resizable=no, location=no, status=no')各参数详解‘/’ :弹出窗⼝的地址;‘newwindow’ :弹出窗⼝的名字(不是⽂件名),⾮必须,可⽤空”代替;height=100 :窗⼝⾼度;width=400 :窗⼝宽度;top=0 :窗⼝距离屏幕上⽅的象素值;left=0 :窗⼝距离屏幕左侧的象素值;toolbar=no :是否显⽰⼯具栏,yes为显⽰;menubar,scrollbars :表⽰菜单栏和滚动栏。
resizable=no :是否允许改变窗⼝⼤⼩,yes为允许;location=no :是否显⽰地址栏,yes为允许;status=no :是否显⽰状态栏内的信息(通常是⽂件已经打开),yes为允许;弹出窗⼝居中⽅法function openWin(url,name,iWidth,iHeight) {//获得窗⼝的垂直位置var iTop = (window.screen.availHeight - 30 - iHeight) / 2;//获得窗⼝的⽔平位置var iLeft = (window.screen.availWidth - 10 - iWidth) / 2;window.open(url, name, 'height=' + iHeight + ',innerHeight=' + iHeight + ' ,width=' + iWidth + ',innerWidth=' + iWidth + ',top=' + iTop + ',left=' + iLeft + ' ,status=no,toolbar=no,menubar=no,location=no,resizable=no,scrollbars=0,titlebar=no');}如何关闭弹出窗⼝?在新打开页⾯中执⾏代码:window.opener = null; window.open('', '_self'); window.close();新窗⼝中关闭代码如下:<input type="button" onclick="window.opener = null; window.open('', '_self'); window.close();" value="关闭" />。
window.open()详解及浏览器兼容性问题
window.open()详解及浏览器兼容性问题⼀、基本语法:window.open(pageURL,name,parameters)其中:pageURL 为⼦窗⼝路径name 为⼦窗⼝名字parameters 为窗⼝参数(各参数⽤逗号分隔)⼆、⽰例<script type="text/javascript">window.open('page.html','newwindow','height=500,width=800,top=0,left=0,toolbar=no,menubar=no,scrollbars=no, resizable=no,location=no, status=no')</script>page.html将在新窗体newwindow中打开,宽为800,⾼为500,距屏顶0象素,屏左0象素,⽆⼯具条,⽆菜单条,⽆滚动条,不可调整⼤⼩,⽆地址栏,⽆状态栏。
各浏览器对window.open()的窗⼝特征sFeatures参数⽀持程度存在差异各浏览器运⾏结果汇总:上表中为各个浏览器对 features 各参数选项的⽀持程度,其中需要特殊说明的如下:【标注1】:IE7 IE8 Firefox Chrome Safari 中,当"menubar"选项为"yes"时,默认不显⽰菜单栏,需要按ALT键后菜单栏才可显⽰;相反当"menubar"选项为"no"时,即使按了ALT键也不会显⽰菜单栏。
【标注2】:Safari中,开启"location"选项与开启"toolbar"选项时显⽰效果⼀致。
【标注3】:IE6 IE8 Chrome 中,使⽤"top"和"left"定位,如果出现设定的的坐标值过⼤,弹出窗⼝将可能显⽰在屏幕可视范围外。
关于“浏览器无法拦截的弹出窗口”、IE、Firefox弹出新窗口
关于“浏览器无法拦截的弹出窗口”、IE、Firefox弹出新窗口大概有很久很久都没有打理这里了,刚朋友问我,如何防止弹出框被浏览器屏蔽,我忽然想到了一个万全之策。
一般来说,我们会用 js 弹出窗口: window.open( url ); 这种方案基本被废弃了,因为所有浏览器都会封杀这种写法。
我要说的有两种方案:1、比如,我们要弹出一个网页:,那么可以构造:<a id=”openWin” href=””></a>然后写脚本,JS写法:document.getElementById(‘openWin’).click();jQuery写法:$(‘#openWin’).click();但这个写法是有问题的,他只能在IE有作用,、非IE浏览器的click() 是无效的,要专门正对非IE浏览器写新的脚本,这跟麻烦。
2、用 <form />构建html:<form id=”openWin”action=””target=”_blank”method=”get”></form>然后写脚本,JS写法:document.getElementById(‘openWin’).submit();jQuery写法:$(‘#openWin’).submit();这种方案,任何浏览器都可以执行,并且不会被任何浏览器以及插件屏蔽。
—- 王子墨 2010 年 3月2012.5.2 日补充:看到留言说,上面方法失效了。
刚才测试了一下,上述方法,在 Firefox 4.0 版本之后已经失效了。
Firefox 为了阻止广告,更加安全,禁止了脚本自动触发 .submit() , .click() 事件。
也就是说,脚本不能在用户不触发事件的时候,不能打开一个新窗口,就是说必须是是用户主动触发 <a /> 的 click() 事件,或者主动触发submit()事件。
所以:<form id=”openWin”action=””target=”_blank”method=”get”></form> ,document.getElementById(‘openWin’).submit();还是会被屏蔽。
- 1、下载文档前请自行甄别文档内容的完整性,平台不提供额外的编辑、内容补充、找答案等附加服务。
- 2、"仅部分预览"的文档,不可在线预览部分如存在完整性等问题,可反馈申请退款(可完整预览的文档不适用该条件!)。
- 3、如文档侵犯您的权益,请联系客服反馈,我们会尽快为您处理(人工客服工作时间:9:00-18:30)。
本文由我司收集整编,推荐下载,如有疑问,请与我司联系
window.open打开弹出而不是窗口
window.open打开弹出而不是窗口- 行为不一致[英]window.open opens pop up and not window - behavior inconsistent In my javascript code I am using the window.open method and the behavior is totally inconsistent: depending on the way I write the code it will either open a new tab or open a pop up window (which is blocked by the pop up blocker). I don’t know how to work around it thanks for your help. The html code:
在我的javascript代码中,我使用window.open方法并且行为完全不一致:根据我编写代码的方式,它将打开一个新选项卡或打开一个弹出窗口(被弹出窗口阻止程序阻止) 。
由于你的帮助,我不知道如何解决它。
HTML代码:
a target=“_blank” Visualiser /a The javascript code:
javascript代码:
function quoteVisu(){ quoteCreate(1); quoteCreate is a method with an AJAX call
quoteCreate是一个带有AJAX调用的方法
function quoteCreate(num_function){ var request=$.ajax({ url: url_up, type: “POST”, beforeSend: function(xhr) {xhr.setRequestHeader(‘X-CSRF-Token’, $(‘meta[name=“csrf-token”]’).attr(‘content’))}, data: {q_param: { title: title, total: total, list: list, client: idclient, tax_rate: tax_rate success: function(data, textStatus, jqXHR) { if (num_function==1){request.done(goShow(data.quote_id))}; if (num_function==0){request.done(goBack());} dataType: “json”return true; and the goShow method:
和goShow方法:
function goShow(quote_id) { var url_visu=“/visu_pdf/quote_visu.”+quote_id window.open(url_visu, ‘_blank’); return true; The code above gives a pop up window which is not the behavior expected. If I put the window.open in the quoteVisu method for example I will have a tab open and not a pop up which is what I want. But if I put it there I don’t have the answer from the JSON which is needed for the new window url.。