[英]Open url in a new window using javascript
I have tried target="_blank"
and other ways so that below window opens in a new page instead of replacing the current page but its not working. 我尝试了
target="_blank"
和其他方法,以使下面的窗口在新页面中打开,而不是替换当前页面,但是它不起作用。
Can someone would be able to help me get this fixed? 有人可以帮助我解决此问题吗?
This is the code I am using: 这是我正在使用的代码:
$("#yes").click(function() {
answer();
setTimeout(function() {
$.cookie("answered", "yes", {path:"/", expires:730});
window.location = "http://www.google.com", "_blank"
}, 2E3)
});
Loads a resource into either a new browsing context (such as a window) or one that already exists, depending on the specified parameters.
根据指定的参数,将资源加载到新的浏览上下文(例如窗口)或已经存在的资源中。
syntax:
句法:
var windowObjectReference = window.open(strUrl, strWindowName[, strWindowFeatures]);
You need to use window.open
instead: 您需要使用
window.open
代替:
window.open('url', 'name', 'window settings')
Check this Online Demo and window open documentation 查看此在线演示和窗口打开文档
name
is optional.name
是可选的。 Specifies the target attribute or the name of the window.指定目标属性或窗口名称。 The following values are supported:
支持以下值:
- _blank - URL is loaded into a new window.
_blank-URL已加载到新窗口中。 This is default
这是默认值
- _parent - URL is loaded into the parent frame
_parent-URL已加载到父框架
- _self - URL replaces the current page
_self-URL替换当前页面
- _top - URL replaces any framesets that may be loaded
_top-URL替换可能加载的所有框架集
or
name
- The name of the window或
name
-窗口名称window settings is optional.
窗口设置是可选的。
window.open()
is a method that you can pass a URL to that you want to open in a new window. window.open()
是一种方法,您可以将URL传递给要在新窗口中打开的URL。 For example: 例如:
window.open() example: window.open()示例:
window.open('http://www.google.com'); //This will open Google in a new window
Additional Information: 附加信息:
window.open()
can be passed additional parameters. window.open()
可以传递其他参数。 See: window.open tutorial 请参阅: window.open教程
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.