javascript打开新窗口问题 [英] javascript open new windows problem

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

问题描述

<script type="text/javascript">
function winopen(e,linkid)
{
   if(document.all)
   {
   leftpos=event.screenX; 
   toppos=event.screenY;
   }
   if(document.layers||document.getElementById)
   {
   leftpos=e.screenX;
   toppos=e.screenY;
   }
   toppos=toppos+10
      MessageWin=eval('window.open(linkid,"newwin",config="width=200,height=100,location=no,status=no,directories=no,toolbar=no,scrollbars=no,menubar=no,resiza ble=no,top='+toppos+',left='+leftpos+'")');
   MessageWin.focus()
}
</script>

<a href="#" onMouseOver="winopen(event,'Default2.aspx')"  önMouseOut="MessageWin.close()">Open Window</a>



这是我的代码,可以在鼠标悬停时打开一个新窗口,并在鼠标悬停时关闭这些窗口.它在谷歌浏览器上工作正常,但在Windows 7的IE中有1个小问题.

如果新窗口在鼠标光标的中心打开,则浏览器将其读取为"onMouseOut",因此这里发生的事情是新窗口保持打开和关闭状态.该怎么解决?
================================================== ==============
已添加



here is my code to open a new window on mouse over and close the windows when mouse out. it working fine at google chrome, but have 1 small problem with IE with windows 7.

if the new windows open at the center of my mouse cursor, the browser read it as ''onMouseOut'', so what happend here is the new windows keep open and close. how to solve this?
=================================================================
Added

var time;

function chkFocus(){

   time = setTimeout(function(){

if(MessageWin.onfocus){

}

else{

   MessageWin.close();

}

}, 100);


并设置我的onmouseover ="chkFocus()";
好吧,问题还是一样,我相信我们几乎可以解决问题.我将超时设置为"100",因为我希望在鼠标超时时立即将其关闭.


and set my onmouseover="chkFocus()";
well, problem still the same, i believe we almost solve the problem. i put timeout as ''100'' because i want it to be closed instantely when mouseout.

推荐答案

您可以使用:
http://jqueryui.com/dialog/ [ ^ ]
将对话框的位置设置为不在链接上方的某个位置,并在鼠标移出时关闭对话框.

还是工具提示?将鼠标悬停在链接上似乎很好.
http://jqueryui.com/tooltip/#tracking [ http://www.thumbalizr.com/apitools.php [ http://livedocs.dojotoolkit.org/dijit/Dialog [ http://dojotoolkit.org/reference-guide/1.8/dijit/Tooltip.html [ ^ ]

我敢打赌它比jQuery还要慢.但这比jQuery UI还漂亮:)
You can use:
http://jqueryui.com/dialog/[^]
Set position of dialog to someplace not over your link and close dialog on mouseout.

Or maybe tooltip? It seems nice for hovering over link.
http://jqueryui.com/tooltip/#tracking[^]

I am not sure what you want to show in those windows. If you want show some info about website from link maybe this will help you?
http://www.thumbalizr.com/apitools.php[^]
It''s creates some nice thumbs of websites. Should work great with tooltip and you could cache those images.

I founding jQuery UI somewhat slow so you could investigate some other libraries or even roll out something on your own.

Check dojo to:
http://livedocs.dojotoolkit.org/dijit/Dialog[^]
http://dojotoolkit.org/reference-guide/1.8/dijit/Tooltip.html[^]

I bet it is even slower then jQuery. But it is even prettier then jQuery UI :)


这就是我的解决方法:
this is how i solve it:
var scrWidth = window.screen.width;
var scrheight = window.screen.height;

var widthPercent = event.screenX / scrWidth * 100
var heightPercent = event.screenY / scrHeight * 100

if(document.all){
   leftpos=event.screenX; 
   toppos=event.screenY;
}

if(document.layers||document.getElementById){
   leftpos=e.screenX;
   toppos=e.screenY;
}

toppos=toppos+10

if(widthPercent > 70){
   leftpos = leftpos * 0.7
}

if(heightPercent > 70){
   toppos = toppos * 0.7
}



这样,如果我的光标位于右下角,则新窗口将出现在左侧.简单但有效:)



by doing this, the new windows will appear at left hand side if my cursor is at the bottom right. simple but efficient :)


这篇关于javascript打开新窗口问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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