基本的Javascript问题:如何打开一个新窗口? [英] Basic Javascript question: How to open a new window?

查看:88
本文介绍了基本的Javascript问题:如何打开一个新窗口?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我试过:

 < a href ='javascript:window.open(testing.html,mywindow,menubar = 0,resizable = 1,width = 200,height = 500,left = 0 ,top = 0);'>新窗口< / a> 

这会导致一个新窗口弹出,但在Firefox中它会留下一个空白窗口的原始页面[对象窗口]。我也遇到了IE问题。



如何打开一个适用于Firefox,IE,Safari和Chrome的窗口?

奖励:如果您可以帮助创建一个javascript可降级的链接(我认为这是一个术语)。 h2_lin>解决方案

通过将脚本放入href属性中,链接将跟随脚本返回值的字符串表示形式。



最向后兼容的方法是将URL和目标作为常规属性放入链接中,并使用onclick事件打开一个窗口,而不是跟随链接。

 < a href =testing.htmltarget = _blankonclick =window.open(this.href,this.target,'menubar = 0,resizable = 1,width = 200,height = 500,left = 0,top = 0'); return false;> ;新窗口< / a> 

如果Javascript在浏览器中被禁用,它将会在链接后面显示,并在新窗口中打开。



使用目标 _blank 打开一个新窗口。


How do I open a new window in javascript properly?

I've tried:

<a href='javascript:window.open("testing.html","mywindow","menubar=0,resizable=1,width=200,height=500,left=0,top=0");' >New Window</a>

This causes a new window to pop up but in Firefox it leaves the original page with a blank window saying "[object Window]". I've also had issues with IE as well.

How can I open a window that works in Firefox, IE, Safari and Chrome?

Bonus: If you can help in creating a link that is javascript degradable (I think that's the term).

解决方案

By putting the script in the href property, the link will follow the string representation of the return value of the script.

The most backwards compatible way is to put the url and target in the link as regular attributes, and use the onclick event to open a window instead of following the link. By returning false from the event you prevent the link from being followed:

<a href="testing.html" target="_blank" onclick="window.open(this.href,this.target,'menubar=0,resizable=1,width=200,height=500,left=0,top=0');return false;">New Window</a>

If Javascript is disabled in the browser, it will follow the link instead and open it in a new window.

Use the target _blank to open a new window.

这篇关于基本的Javascript问题:如何打开一个新窗口?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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