开发者

how to remove body onload function in java script?

I met one critical problem in java script .....help me to fix this.......

i have written the onload function in one jsp page say login.jsp...

in tat function i used window.open method to open a new window again with the same jsp page login.jsp with disabling the toolbars......

now wat happening is when iam opening same page again in new window obviously tat body onload function will again get called and opens开发者_开发百科 a new window in indefinite........

but what i want is, i have to remove that onload function in tat jsp page once a new window is opened..

Is it possible to remove tat onload function while getting opened in the new window??

could anyone please come up with an idea or little bit of code to do this using java script??


Since it's the same page a quick workaround could be to check if the current window has been opened programmatically, before executing window.open, something like this:

window.onload = function () {
  if (!window.opener) {
    window.open(/*...*/);
  }
};

The above code checks if the window.opener property has a value.

This property contains a reference to the window that opened this current window, and of course if the current window hasn't been opened programmatically, it will contain null.

In conclusion, the window.open method will be invoked only once.


It seems you're going about this the wrong way.

Although there may be a way to intercept the onload function before it actually runs (some javascript libraries can help you to add a handler to the OnDocumentReady event), but maybe you should be doing something serverside. For example - If you want NOT to popup the window in the second window, then one way is to set a querystring parameter telling the server not to add that attribute to the body tag.

You could also check the referrer. If the user is coming from that page, then don't add the attribute to the body tag.


Try having the popup JSP look to see whether you're coming from the problematic page. If so, set window.onload = null -- better yet, don't set anything at all in that JSP.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜