onBlur

JavaScript and client side scripting.

Moderator: General Moderators

Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

onBlur

Post by Shendemiar »

I have links with anchors to popupped windows, but it's no good if the pop up stays behind the main windows.

For solution i've used <body onblur=windows.close> So the pop ups close when they are not looked at anymore. And pop up again to the front if links are pressed.

This works fine but it's not valid html/javascript. Is there any legal way to close window when it loses it's focus? Or to make pop up window came in front when it's contents update?
onBlur = myJavaScriptCode

Event handler for Button, Checkbox, FileUpload, Layer, Password, Radio, Reset, Select, Submit, Text, TextArea, Window.
See, it's not legal for body, thou all browsers i use supports it anyway. (Execpt IE who closes the popup window if link is clicked)

What's the layer?

How could the obBlur be triggered by Window?
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post by Shendemiar »

Code: Select all

<SCRIPT type="text/javascript">
<!--
Window.onBlur="alert("Blur")"
-->
</SCRIPT>
Does nothing.

How can i trigger the window.onBlur
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post by Shendemiar »

Code: Select all

<A HREF="./" 

onClick="MyWindow=window.open('index.php?MM=sanasto_kielet',

'SanastoKielet','toolbar=no'); MyWindow.focus; return false;)"

>
What do i need to add to close a windows named SanastoKielet if one exists Or make it really get focus if it's allready open.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

try something like this:

Code: Select all

function closeMe()
&#123;
  window.close();
&#125;

window.onblur = closeMe;
you can edit your posts, you know.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

If I try ur code in IE it reports an error "Not Implemented!"
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post by Shendemiar »

n00b Saibot wrote:If I try ur code in IE it reports an error "Not Implemented!"
Not for me. I had success with feyds code, but i don't still understand why it works while

window.onblur ="window.close"

doesn't
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

yer wrong! it works only when window refers to the parent window. when i changed it to refer to the opened window the code had no effect at all. :(

can ya tell me how it works in ur case...
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post by Shendemiar »

n00b Saibot wrote:yer wrong! it works only when window refers to the parent window. when i changed it to refer to the opened window the code had no effect at all. :(

can ya tell me how it works in ur case...
I have these:

In heaad

Code: Select all

<!-- JavaScript -->
<SCRIPT type="text/javascript">
<!--
function closeMe()
&#123;
  window.close();
&#125;
-->
</SCRIPT>
<!-- JavaScript -->
In Body

Code: Select all

<!-- JavaScript -->
<SCRIPT type="text/javascript">
<!--
window.self.name = "<?=$Wname?>";
<?=$Blur?>
-->
</SCRIPT>
<!-- JavaScript -->
Where
$Wname = "just some name"
$Blur = "window.onblur = closeMe;\n"
Last edited by Shendemiar on Fri Dec 31, 2004 5:51 am, edited 2 times in total.
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post by Shendemiar »

Ok, now i have the onblur->close done legally, but i still have problem.

In IE: Clicking on a link (or anywhere in the page) closes the popup before the link opens.

In Firefox: Losing a focus makes nothing happen. (I don't care about this)

In Opera: Works perfectly in all aspects.

How come the window loses the focus if a text inside the window is clicked?
Any way around this?
Last edited by Shendemiar on Fri Dec 31, 2004 5:57 am, edited 1 time in total.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

Yes, that's the thing happening to me all the time in IE since i am trying to solve ur code
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

technically, each textbox is a window too. that's why it loses focus. Although, I don't remember the blur event getting called when that happened, as that's just a windows thing.
dreamline
Forum Contributor
Posts: 158
Joined: Fri May 28, 2004 2:37 am

Post by dreamline »

I'm having the same prob, and i'm also still working on a solution.. If i find one i'll post a reply again... :D
Shendemiar
Forum Contributor
Posts: 404
Joined: Thu Jan 08, 2004 8:28 am

Post by Shendemiar »

feyd wrote:technically, each textbox is a window too. that's why it loses focus. Although, I don't remember the blur event getting called when that happened, as that's just a windows thing.
Windows thing or IE thing? It does not happen on Fireofx or Opera. And clicking on any part of the page makes it happen, not just textboxes.
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

Textboxes, buttons, dialogue boxes, all kinds of stuff are windows in Windows. This may be true in other OS's as well, I'm not sure.

The reason you only get it in IE is likely because of the event model used. Although I can't say for sure, in any real direction.
User avatar
n00b Saibot
DevNet Resident
Posts: 1452
Joined: Fri Dec 24, 2004 2:59 am
Location: Lucknow, UP, India
Contact:

Post by n00b Saibot »

Yeah, that's right. imo the true culprit in IE is the event model :)
Post Reply