open.window重新加载父窗口 [英] open.window reloads parent window

查看:74
本文介绍了open.window重新加载父窗口的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Netscape中执行以下行时,弹出窗口会按原样加载,

但父窗口通常(但并非总是如此)重新加载。


< a href ="#"

onClick =" window.open(''/ cgi-bin / displayimage.cgi?/ store/demo/image.jpg& YOUR + PRODUCT%27< b> S + NAME + GOES'',

''fullimage'',''WIDTH = 420,HEIGHT = 405,status = 0'')">


原始窗口不应该重新加载,但是,我已经用

版本4.72和7.02进行了测试,他们都这样做了。 IE不会这样做。

最大的问题是原始窗口内置了安全性

所以它必须从正确的引用URL调用,但是当Netscape

重新加载这个父窗口,它忽略发送原始的引用

url,所以原来的页面会被一个错误页面替换为
$ b $点击链接上方的b。


是否有任何解决方法,其中Netscape不会重新加载

原始页面,或者如果它,至少不要丢失推荐网址?


谢谢,


马歇尔

解决方案



" Marshall Dudley" < MD ***** @ king-cart.com>在消息中写道

news:40 *************** @ king-cart.com ...

当我这样做时在Netscape中的下一行,弹出窗口按原样加载,
但父窗口通常(但不总是)重新加载。

< a href ="#"

onClick =" window.open(''/ cgi-bin / displayimage.cgi?/store/demo/image.jpg& YOUR + P

RODUCT%27< b> ; S + NAME + GOES'',''fullimage'',''WIDTH = 420,HEIGHT = 405,status = 0'')>

原始窗口不应重新加载,但是,我已经用版本4.72和7.02进行了测试,他们都做到了。 IE不会这样做。
最大的问题是原始窗口内置了安全性
所以它必须从正确的引用URL调用,但是当Netscape重新加载这个父窗口时,它忽略了发送原始的引用URL,所以只要点击上面的链接就会将原始页面替换为错误页面。

是否有任何解决方法,哪个Netscape都不会重新加载原始页面,或者如果确实如此,至少不会丢失引用网址?

谢谢,

Marshall



Onclick应返回false以防止重新加载。


Silvio Bierman


Marshall Dudley写道:

< a href ="#"

onClick =" window.open(''/ cgi-bin / displayimage.cgi? /store/demo/image.jpg&YOUR+P

RODUCT%27< b> S + NAME + GOES'',''fullimage'',''WIDTH = 420,HEIGHT = 405,状态= 0 '') ">




更好地了解onClick处理程序的功能

会让你意识到问题...


当< a>中存在onClick处理程序时,它会在浏览器触发之前触发

导航到href url。它运行在

onClick处理程序中指定的任何脚本,然后_Based返回值_导航到

href。


也就是说,浏览器希望onClick中的代码返回true或

false。如果为true,它将导航到href。如果为false,它将停止

处理_not_导航到href。


所以在你的情况下,你会想要这样做:

< a href ="#" onClick =" window.open(...); return false;">


这样,无论如何,onClick总是会返回false,而#

href永远不会导航到。


现在,一个重要的注释:

使用#因为你的href url可能会产生误导,因为它会在许多浏览器中重新加载

。此外,对于没有启用js的用户,它将执行

什么都没有,并且没有提供有用的信息。更好的方法是

< a href =" /note_about_javascript_being_required.html" onClick =" ...;返回

false;">

这样,非js用户至少会被带到通知他们的页面

为什么链接没有按预期工作。


< FAQENTRY>因为我希望在常见问题解答中更详细地介绍这个内容,但它不是......这样的常见问题应该更好地解决

常见问题,IMO。


-

Matt Kruse

Javascript工具箱: http://www.JavascriptToolbox.com/


Marshall Dudley说:< blockquote class =post_quotes>
当我在Netscape中执行以下行时,弹出窗口按原样加载,
但父窗口通常(但不总是)重新加载。

< a href ="#"
onClick =" window.open(''/ cgi-bin / displayimage.cgi?/store/demo/image.jpg& YOUR + PRODUCT%27< ; b> S + NAME + GOES'',
''fullimage'',''WIDTH = 420,HEIGHT = 405,status = 0'')">

原始窗口不应该重新加载,但是,我已经用版本4.72和7.02进行了测试,他们都做了。 IE不会这样做。
最大的问题是原始窗口内置了安全性
所以它必须从正确的引用URL调用,但是当Netscape重新加载这个父窗口时,它忽略了发送原始的引用URL,所以只要点击上面的链接就会将原始页面替换为错误页面。

是否有任何解决方法,哪个Netscape不会重新加载原始页面,或者如果它,至少不会丢失引用URL?




解决方法是停止告诉浏览器重新加载页面。


除非onClick事件处理程序返回false,否则链接将是

。链接是#,这是当前页面的顶部。


正如您所发现的,某些浏览器会选择猜猜您可能是什么? b $ b想要发生,而不是做你实际告诉他们的事情。


要纠正它,请添加:

;返回false

就在您的onclick属性的结束报价之前。


When I do the following line in Netscape, the popup loads as it should,
but the parent window usually, but not always, reloads as well.

<a href="#"
onClick="window.open(''/cgi-bin/displayimage.cgi?/store/demo/image.jpg&YOUR+PRODUCT%27<b>S+NAME+GOES'',
''fullimage'', ''WIDTH=420,HEIGHT=405,status=0'')">

The original window should not reload, but is, and I have tested it with
both version 4.72 and 7.02, and they both do it. IE does not do it.
The big problem is that the original window has security built into it
so it must be called from the right referring url, but when Netscape
reloads this parent window, it neglects to send the original referring
url, so the original page is replaced with an error page as soon as the
above link is clicked.

Is there any workaround for this, where either Netscape will not reload
the original page, or if it does, at least not lose the referring url?

Thanks,

Marshall

解决方案


"Marshall Dudley" <md*****@king-cart.com> wrote in message
news:40***************@king-cart.com...

When I do the following line in Netscape, the popup loads as it should,
but the parent window usually, but not always, reloads as well.

<a href="#"
onClick="window.open(''/cgi-bin/displayimage.cgi?/store/demo/image.jpg&YOUR+P
RODUCT%27<b>S+NAME+GOES'', ''fullimage'', ''WIDTH=420,HEIGHT=405,status=0'')">

The original window should not reload, but is, and I have tested it with
both version 4.72 and 7.02, and they both do it. IE does not do it.
The big problem is that the original window has security built into it
so it must be called from the right referring url, but when Netscape
reloads this parent window, it neglects to send the original referring
url, so the original page is replaced with an error page as soon as the
above link is clicked.

Is there any workaround for this, where either Netscape will not reload
the original page, or if it does, at least not lose the referring url?

Thanks,

Marshall



Onclick should return false to prevent a reload.

Silvio Bierman


Marshall Dudley wrote:

<a href="#"
onClick="window.open(''/cgi-bin/displayimage.cgi?/store/demo/image.jpg&YOUR+P
RODUCT%27<b>S+NAME+GOES'', ''fullimage'', ''WIDTH=420,HEIGHT=405,status=0'')">



Having a better understanding of the functionality of the onClick handler
will make you realize the problem...

When an onClick handler exists in an <a>, it is fired before the browser
navigates to the href url. It runs whatever script is specified in the
onClick handler, then _based on the return value_ either navigates to the
href or not.

That is, a browser expects the code within onClick to return either true or
false. If true, it will navigate to the href. If false, it will stop
processing an _not_ navigate to the href.

So in your situation, you would want to do:
<a href="#" onClick="window.open(...);return false;">

That way, the onClick will always return false no matter what, and the "#"
href will never be navigated to.

Now, an important note:
Using "#" as your href url can be misleading, because it will simply cause a
reload in many browsers. Also, for users without js enabled, it will do
nothing and give no useful information. A better way to do it is
<a href="/note_about_javascript_being_required.html" onClick="...;return
false;">
That way, non-js users will at least be taken to a page which informs them
of why the link didn''t work as expected.

<FAQENTRY> because I expected to see this covered in more detail in the FAQ
but it wasn''t... such a common problem should be addressed a little better
in the FAQ, IMO.

--
Matt Kruse
Javascript Toolbox: http://www.JavascriptToolbox.com/


Marshall Dudley said:


When I do the following line in Netscape, the popup loads as it should,
but the parent window usually, but not always, reloads as well.

<a href="#"
onClick="window.open(''/cgi-bin/displayimage.cgi?/store/demo/image.jpg&YOUR+PRODUCT%27<b>S+NAME+GOES'',
''fullimage'', ''WIDTH=420,HEIGHT=405,status=0'')">

The original window should not reload, but is, and I have tested it with
both version 4.72 and 7.02, and they both do it. IE does not do it.
The big problem is that the original window has security built into it
so it must be called from the right referring url, but when Netscape
reloads this parent window, it neglects to send the original referring
url, so the original page is replaced with an error page as soon as the
above link is clicked.

Is there any workaround for this, where either Netscape will not reload
the original page, or if it does, at least not lose the referring url?



The workaround is to stop telling the browser to reload the page.

Unless the onClick event handler returns false, the link will be
followed. The link is "#", which is the top of the current page.

As you''ve found, some browsers choose to guess what you probably
want to happen, rather than doing what you actually tell them.

To correct it, add:
;return false
just before the closing quote of your onclick attribute.


这篇关于open.window重新加载父窗口的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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