/    Sign up×
Community /Pin to ProfileBookmark

onmouseover/onclick

Ran into interesting problem in javascript – trying to open a popup on mouseover and close it on mouseout.
The window opens when ‘onclick’ is coded and occurs and it closes when mouseout occurs.
It does not open when ‘onmouseover’ is coded and occurs (onmouseout throws error because ‘chyld’ is not valued)

Why should onClick work and onMouseOver not work?
( BTW:
same occurs if event’s element is ‘<A…’ instead of ‘<IMG’….
same occurs on Win2K and WinXP using NS7 and IE6

*** IT WORKS FINE IN OPERA 7.11 ***

<script type=”text/javascript”>
var chyld = “”
function openwin()
{
chyld = window.open(“helpcall.html”, “miniwin”, “scrollbars=auto, resizable=false, left=10, screenx=10, top=120, screeny=120, width=420, height=420”) ;
}
function closewin()
{
chyld.window.close()
}
</script>

THIS WORKS
<img src=”img1.gif” border=0 onclick=”openwin(); return false;” onMouseOut=”closewin(); return false;”>

THIS DOESN’T WORK:
<img src=”img2.gif” border=0 onMouseOver=”openwin(); return false;” onMouseOut=”closewin(); return false;”>

to post a comment
JavaScript

6 Comments(s)

Copy linkTweet thisAlerts:
@VladdyJul 14.2004 — Won't work with popup blockers in either case.

That is one annoying application to begin with and no sane person will stay on such site nor come back to it.

Stop wasting your time and find a better solution to whatever problem you got.
Copy linkTweet thisAlerts:
@steeleweedauthorJul 14.2004 — First, I can't tell you how many pieces of code I have written and debugged for a whim, for play or for execise which later was used to solve major production problems. After 40+ years of coding, I have learned that no programming is really wasted, if only of educational value.

Second, this is for an intranet informational site and popups are not normally blocked for this site by our employees.

I have an image which is a diagram containing multiple components. Want to provide details on the various components of the diagram. Question is how best to provide that info.

I could build an imagemap and link to new pages, one for each component, but don't want the explanation of a component to overlay the diagram and don't want user to have to click 'close' or 'back' to return to the diagram. Positioning the image on the right and opening popups on the left allows me to control the size of the 'detail' window and user closes one simply by moving mouse off that particular component on the diagram and, if desired, to the next component. Simple and fast way to access the info the user wants and yet have it explained within the context of the entire diagram.

You have other ideas on how to to this?
Copy linkTweet thisAlerts:
@steeleweedauthorJul 14.2004 — BTW: Building imagemap with

<A href=# TITLE="details">&nbsp</a>

would work for IE, but we run multiple platforms and browsers.
Copy linkTweet thisAlerts:
@russellJul 14.2004 — Never thought I'd EVER say this, but a frameset might be just the thing here (owww, that hurts to say). You can control the href of one frame via the onmouseover/onmouseout event handlers of the other. I was going to suggest a DHTML solution, but the multiple broweser platform situation will make that a bit trickier to code (though still a viable solution).

If you do change urls on mouseover/out events, I'd reccomend setting a timeout, that can be cleared. In other words, make 'em hover for a full second to display the content, otherwise you'll be constantly navigating when someone casually drags their mouse accross the image.
Copy linkTweet thisAlerts:
@russellJul 14.2004 — <i>
</i>var targetURL;
var v = null;

function navigate2(url) {
targetURL = url;
v = setTimeout("changeLocation()", 1000);
}

function changeLocation() {
parent.frames["FrameNameOrIndex"].location.href=targetURL;
}

function clearIt() {
if(v)
clearInterval(v)
v = null;
}

...

&lt;img src="img.gif" onmouseover="navigate2('detailURL.html')" onmouseout="clearIt()"&gt;
Copy linkTweet thisAlerts:
@steeleweedauthorJul 14.2004 — Your code may well be the best way to handle it...good tip re requiring some 'hover time'.

I also dislike frames - so much I didn't even consider that method, but I guess everything has its uses, even frames. Will get busy coding and see how it looks.

Thanks for the idea
×

Success!

Help @steeleweed spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 5.18,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,

tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,
)...