• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 561
  • Last Modified:

onBlur problems

In my page I have this line of code

<body onBlur="self.close()" style="margin: 0px">


In firefox when someone right clicks the page stays open but in IE it closes, how can I stop it from closing?
0
levyuk
Asked:
levyuk
  • 6
  • 4
  • 2
  • +1
1 Solution
 
ZvonkoSystems architectCommented:
Check this:

<body onBlur="self.close()" onContextMenu="return false;" style="margin: 0px">

0
 
mshogrenCommented:
What do you need this onBlur for?  It attempts to close the page in Firefox too, according to the Javascript console, but the security settings of Firefox prevent that.  If you wish to stop the page from closing in all browsers try this:

<body style="margin: 0px">
0
 
levyukAuthor Commented:
Well its a pop-up window that displays an image. So when someone clicks off the window it closes
0
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
levyukAuthor Commented:
The onContextMenu creates it's on problems. The user is now no longer able to save the image
0
 
ZvonkoSystems architectCommented:
How about this:
<script>cm=false</script>
<body onBlur="if(!cm)self.close()" onContextMenu="cm=true;setTimeout('self.focus();cm=false;',3000)" style="margin: 0px">


0
 
levyukAuthor Commented:
Doesn't work in IE
0
 
Pravin AsarCommented:
How about this

<body topmargin="0" onBlur="if (window.event.type.match('contextmenu')) { return false;} else  { self.close(); }" style="margin: 0px">

0
 
levyukAuthor Commented:
Nope doesn't work
0
 
Pravin AsarCommented:
>> In firefox when someone right clicks the page stays open but in IE it closes, how can I stop it from closing?

<script language="javascript">
function NeedClose(evt) {
    if (!evt) { evt = window.event; }
    if (evt.type.match('blur')) {
          self.close();
    }
}
</script>
</head>

<body topmargin="0" onBlur="NeedClose(event);" style="margin: 0px">
0
 
levyukAuthor Commented:
Ok the problem is I need it to close when the person clicks off the page. The page is a popup window and when the user clicks off the window I want it to close. However I don't want it to close when they right click, the problem is the page losses focus when the right click is performed thereby closing. I have a feeling this is not going to work.
0
 
Pravin AsarCommented:
When you click right click , it is not losing a focus

When a user does RMB  (Righ Mouse Button) click the event type = contextmenu

 
0
 
levyukAuthor Commented:
So why does the window close in IE if it is not losing focus?
0
 
Pravin AsarCommented:
Here is something for you to try ..
Click on the links will open a new window,
RMB on Newly opened window will not close the window.
Only when it looses focus , it is automatically closed.

This code does work with IE, FF, NS


<html>
<head>
<title>Window Open Page (winopen.htm)
</title>
<script language="javascript">
function OpenNewWindow(lnk) {
   window.open (lnk, 'NewWindow', "width=300, height=300, toolbar=no, status=no");
      return false;
}
</script>
</head>

<body topmargin="0" style="margin: 0px">
<a href="#" onclick="return OpenNewWindow('winclose.htm');">Click to Open New Window</a>
</body>
</html>

FILE : winclose.htm

<html>

<head>
<title>New window (winclose.htm)
</title>
<script language="javascript">
function NeedClose(evt) {
   if (!evt) { evt = window.event; }
         if (evt.type.match('blur')) {
               self.close();
      }
}
</script>
</head>

<body topmargin="0" onBlur="NeedClose(event);" style="margin: 0px">

<h1>NEW WINDOW</h1>

</body>

</html>




0

Featured Post

Free Tool: Port Scanner

Check which ports are open to the outside world. Helps make sure that your firewall rules are working as intended.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

  • 6
  • 4
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now