如何打开新窗口 [英] how to open new window

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

问题描述

嗨!


我用过JS,但我还是新手。


我有这样的东西:


oNewWindow = new Object();

oNewWindow = open(" sonnich.xls"," Qopen"," resizable = yes,scroll = y es,

status = yes,width = 320px,height = 470px",true);

oNewWindow.focus();


和我需要让它工作,所以它总是打开一个新窗口(它是

a函数)。


我试过oNewWindow = null ,但是没有这样做


Sonnich

解决方案

这是'代码我用来弹出一个新窗口。这是我的应用程序特定的

,但您可以根据您的规格进行更改。我有另外一个函数setField,它从弹出窗口调用,将

值返回到opener中。窗口。


祝你好运,Rob: - ]

var newwindow = undefined;


//打开弹出窗口窗口。使用函数setField允许值通过opener返回



函数popitup(url,width,height)

{

var h =''350'';

var w =''300'';

if(width&& width .length> 0)

w =宽度;

if(height&& height.length> 0)

h = height;

// alert(url); //用于调试

if(newwindow&&!newwindow.closed&& newwindow.location)

//如果我们已经打开一个弹出窗口,我们它

{

newwindow.location.href = url;

}

else //创建一个新的弹出窗口

{

newwindow = window.open(url,''name'',''height =''+ h +'',width =''+ w + '',

menubar = yes location = yes resizable = yes scrollbars = yes'');

if(!newwindow.opener)newwindow.opener = self; // IE hack

}

if(newwindow.focus){newwindow.focus()}

返回false;

}


Sonnichaécrit:


我有类似的东西:

oNewWindow = new Object();


如果你告诉oNewWindow是新的,当然是新的(窗口)

oNewWindow = open(" sonnich.xls"," Qopen" ,resizable = yes,scroll = y es,
status = yes,width = 320px,height = 470px",true);
oNewWindow.focus();

我需要让它工作,它总是打开一个新窗口(它是一个函数)。

我已经尝试过oNewWindow = null,但是没有这样做




简单地说:

if(oNewWindow!= null&&!oNewWindow.closed)

oNewWindow = window .open(" sonni ...);

else

oNewWindow.location =''fathernich.htm'';

oNewWindow。 focus();

函数Pop(页){

if(foo!= null&&!foo.closed)

foo = window.open('''','''',''width = 320,height = 470,status = 1,srollbars = 1,resizable = 1'')

foo.location =页;

foo.focus();

}


< a href = " sonnich.xls"

onclick =" Pop(this.href);返回false;"> sonnich< / a>

-

Stephane Moriaux et son [moins] vieux Mac


Sonnichaécrit:

嗨!

我使用过JS,但我还是新手。

您需要知道的一切(包括语法和工作示例)是

提供于:

http://developer.mozilla.org/en/docs/DOM:window.open

我有这样的事情:

oNewWindow = new Object();


您不需要创建新的Object()。

oNewWindow = open(" sonnich.xls"," Qopen"," resizable = yes,scroll = y es,
status = yes,width = 320px,height = 470px",true);


1-如果调用open()方法,在某些情况下/ context,方法

将链接到文档而不是窗口对象。因此,总是将调用范围限定为窗口对象更好




2- scroll不是有效的windowFeature;滚动条是。


3- windowFeatures之间应该没有空格


4-宽度和高度不占用px


5-没有第四个参数:你的真实参数将被忽略。


6-请注意,引用的资源是一个特定的内容类型,如果是的话,它应该打开MS-Excel安装在远程系统上。

你应该相应地警告你的用户。


"你总是需要在链接到文件时提供*明确的警告

以任何其他格式而不是HTML *,至少有两个原因:

o用户可能没有安装必要的软件而且非常好

不礼貌让他们等待(这些文件通常比简单的大b / b
HTML)对于他们不能使用的东西

o非标准文件格式会导致非标准行为:对于

示例,PDF文件将启动Acrobat(如果用户安装了它,当然是
),从而给用户一个令人讨厌的惊喜甚至更长的等待和新的和不同的界面控件的出现

J. Nielsen

无警告地链接到非标准文件
http:/ /www.useit.com/alertbox/990530_comments.html

oNewWindow.focus();



如果窗口不存在,那么它将被创建并将在开场白的顶部

。所以,你的oNewWindow.focus()调用是不合适的。

你应该检查
http://developer.mozilla.org/en/docs/DOM:window.open


更加明智/恰当地使用焦点()。
$ b $bGérard

-

删除等等给我发电子邮件


Hi!

I have used JS, but I am still new to it.

I have something like this:

oNewWindow = new Object();
oNewWindow = open("sonnich.xls","Qopen","resizable=yes,scroll=y es,
status=yes, width=320px, height=470px",true);
oNewWindow.focus();

and I need to make it work so, that it always opens a new window (it is
a function).

I have tried oNewWindow=null, but that does not do it

Sonnich

解决方案

Here''s the code I use to popup a new window. It''s kind of specific to
my application but you can change it to your specifications. I have
another function, setField, which is called from the popup to return a
value into the "opener" window.

Good luck, Rob:-]
var newwindow = undefined;

// Open popup window. Works with function setField to allow a value to
be returned via "opener"
function popitup(url, width, height)
{
var h = ''350'';
var w = ''300'';
if(width && width.length > 0)
w = width;
if(height && height.length > 0)
h = height;
// alert(url); // for debugging
if (newwindow && !newwindow.closed && newwindow.location)
// If we have a popup already open, us it
{
newwindow.location.href = url;
}
else // create a new popup
{
newwindow=window.open(url,''name'',''height='' + h + '',width='' + w + '',
menubar=yes location=yes resizable=yes scrollbars=yes'');
if (!newwindow.opener) newwindow.opener = self; // IE hack
}
if (newwindow.focus) {newwindow.focus()}
return false;
}


Sonnich a écrit :


I have something like this:

oNewWindow = new Object();
if you tell oNewWindow is new, of course it is new (window)
oNewWindow = open("sonnich.xls","Qopen","resizable=yes,scroll=y es,
status=yes, width=320px, height=470px",true);
oNewWindow.focus();

and I need to make it work so, that it always opens a new window (it is
a function).

I have tried oNewWindow=null, but that does not do it



simply :
if(oNewWindow!=null && !oNewWindow.closed)
oNewWindow = window.open("sonni ... );
else
oNewWindow.location = ''fathernich.htm'';
oNewWindow.focus();
function Pop(page) {
if(foo!=null && !foo.closed)
foo=window.open('''','''',''width=320,height=470,status =1,srollbars=1,resizable=1'')
foo.location=page;
foo.focus();
}

<a href="sonnich.xls"
onclick="Pop(this.href); return false;">sonnich</a>

--
Stephane Moriaux et son [moins] vieux Mac


Sonnich a écrit :

Hi!

I have used JS, but I am still new to it.

Everything you need to know (including syntax and working examples) are
provided at:

http://developer.mozilla.org/en/docs/DOM:window.open
I have something like this:

oNewWindow = new Object();
You do not need to create a new Object().
oNewWindow = open("sonnich.xls","Qopen","resizable=yes,scroll=y es,
status=yes, width=320px, height=470px",true);
1- if the open() method is called, in some cases/context, the method
will link to the document and not to the window object. So, it''s better
to always scope the call to the window object.

2- scroll is not a valid windowFeature; scrollbars is.

3- there should be no blank space between windowFeatures

4- width and height take no "px"

5- there is no 4th argument: your "true" argument will be ignored.

6- Note that the referenced resource is a specific content-type which is
supposed to open up MS-Excel if it is installed on the remote ssystem.
You should warn accordingly your users about this.

"You always need to provide an *explicit warning when linking to files
in any other format than HTML* for at least two reasons:
o the user may not have the necessary software installed and it is very
impolite to make them wait (these files are usually bigger than simple
HTML) for something they can''t use
o the non-standard file format will cause a non-standard behavior: for
example, a PDF file will start up Acrobat (if the user has it installed,
of course), thus giving users a nasty surprise in terms of an even
longer wait and the appearance of new and different interface controls"
J. Nielsen
Linking to Non-Standard Files Without Warning
http://www.useit.com/alertbox/990530_comments.html
oNewWindow.focus();


If the window does not exist, then it will be created and will be on top
of the opener. So, your oNewWindow.focus() call here is inappropriate.
You should examine the examples at
http://developer.mozilla.org/en/docs/DOM:window.open

for a more judicious/appropriate use of focus().
Gérard
--
remove blah to email me


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

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