V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
V2EX 提问指南
cfan365
V2EX  ›  问与答

js如何自动click某个位置中的固定坐标?

  •  
  •   cfan365 · 2011-11-30 00:21:02 +08:00 · 6041 次点击
    这是一个创建于 4549 天前的主题,其中的信息可能已经有所发展或是发生改变。
    <div id="dom1" style="width:100px;height:50px;"><embed width="100" height="50" wmode="transparent" type="application/x-shockwave-flash" src="play.swf"></div>

    play.swf的大小是100*50,显示在dom1这个div中,在play.swf的坐标80*25的地方,有一个播放按钮,我要实现那个播放按钮的位置被自动点击一下,如何实现呢?

    dom1在页面中的位置是可以获取到的吧?
    4 条回复    1970-01-01 08:00:00 +08:00
    keakon
        1
    keakon  
       2011-11-30 00:38:16 +08:00
    没法实现,JavaScript的执行环境和Flash不同,它只知道DOM元素,不知道Flash容器里的按钮是什么玩意。必须由后者在ExternalInterface中注册一个函数,将API暴露出来后,才能让前者调用。
    arzusyume
        2
    arzusyume  
       2011-11-30 09:08:16 +08:00
    点击flash上的地方用as实现,
    如果是想点击dom中的某一区域坐标可以给body绑定click事件,从返回的event中获取点击点的坐标再判断是否处于区域内
    cfan365
        3
    cfan365  
    OP
       2011-11-30 11:26:15 +08:00
    @arzusyume 应该是这个思路 这个有实现的案例吗?
    arzusyume
        4
    arzusyume  
       2011-12-01 11:20:06 +08:00
    @cfan365
    以下代码是按照LZ的判断点击坐标...虽然建一个隐藏div判断是否点击了这个div要更正常些

    <!DOCTYPE>
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>Test</title>
    </head>
    <script type="text/javascript">
    var bind = function(obj, action, func) {
    if (window.addEventListener) {
    obj.addEventListener( action, function(event) {
    func(obj, event);
    }, false);
    } else if (window.attachEvent) { //IE
    obj.attachEvent('on' +action, function(event) {
    func(obj, event);
    });
    }
    }

    var callBack = function(obj, event) {
    console.info(event);
    if (event.clientX < 40 || event.clientX > 120) {
    return;
    }
    if (event.clientY < 120 || event.clientY > 220) {
    return;
    }
    alert('click in box!');
    }
    </script>
    <body style="width:100%;height:100%;">
    <div style="border: 1px solid;height: 100px;left: 40px;position: absolute;top: 120px;width: 100px;"></div>

    <script type="text/javascript">
    bind(document.body, 'click', callBack);
    </script>
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   实用小工具   ·   1863 人在线   最高记录 6547   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 23ms · UTC 16:29 · PVG 00:29 · LAX 09:29 · JFK 12:29
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.