谷歌浏览器“window.open"解决方法? [英] Google Chrome "window.open" workaround?

查看:312
本文介绍了谷歌浏览器“window.open"解决方法?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我一直在开发一个网络应用程序,其中的一部分我需要打开一个新窗口.我在所有浏览器上都可以使用它,我的症结在于谷歌浏览器.

I have been working on a web app and for part of it I need to open a new window. I have this working on all browsers, my sticking point is with Google Chrome.

Chrome 似乎忽略了导致我出现问题的窗口功能,我遇到的问题是我需要在新窗口中可以编辑地址栏.FF、IE、Safari 和 Opera 可以做到这一点,而 Chrome 则不然.

Chrome seems to ignore the window features which is causing me issues, the thing I'm struggling with is I need the address bar to be editable within the new window. FF, IE, Safari and Opera do this fine, Chrome does not.

我的代码:

function popitup(url) {
  newwindow=window.open(url, 'name', 'toolbar=1,scrollbars=1,location=1,statusbar=0,menubar=1,resizable=1,width=800,height=600');
  if (window.focus) {
    newwindow.focus()
  }
  return false;
}

推荐答案

其他答案已经过时.Chrome for window.open 的行为取决于调用它的位置.另请参阅本主题.

The other answers are outdated. The behavior of Chrome for window.open depends on where it is called from. See also this topic.

当从通过用户操作(例如 onclick 事件)触发的处理程序调用 window.open 时,它的行为类似于 ,默认情况下在新选项卡中打开.但是,如果在别处调用 window.open,Chrome 会忽略其他参数并始终打开一个带有不可编辑地址栏的新窗口.

When window.open is called from a handler that was triggered though a user action (e.g. onclick event), it will behave similar as <a target="_blank">, which by default opens in a new tab. However if window.open is called elsewhere, Chrome ignores other arguments and always opens a new window with a non-editable address bar.

这看起来像是某种安全措施,但其背后的原理尚不完全清楚.

This looks like some kind of security measure, although the rationale behind it is not completely clear.

这篇关于谷歌浏览器“window.open"解决方法?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆