比如有一个链接:http://www.abc.com/123.html两种设想:①当浏览者用鼠标去“拖选”该链接时,JS代码就监控到,然后立即另开一个窗口打开该链接或者②当浏览者选定了该链接上的任何字符,再当他按CTRL+V 或者直接选择“复制”时,也会立即另开一个窗口打开该链接

解决方案 »

  1.   


    <div id="div1">
    <a href="http://hi.csdn.net/sohightthesky" ondrag="return doDrag(this)">手动?</a>
    </div>
    </body>
    <script type="text/javascript">
    var doDrag=function(obj) {
        window.open(obj.href);
        return false;
    }
    </script>
      

  2.   

    <html>
    <head>
    </head>
    <body>
    <a id="TestLink" href="http://www.csdn.net">csdn</a>
    <script>
    var testLink = document.getElementById("TestLink");
    testLink.attachEvent("onmouseover",mouseEnter);
    function mouseEnter(){
    var e = event;
    var src = e.srcElement;
    var id = src.id;
    openWindow(src.href);
    }function openWindow(url){
    window.open(url,"","");
    }
    </script>
    </body>
    </html>
      

  3.   

    firefox 不是有dragdrop事件么,用那个好了,不要用mouseover太那个了
      

  4.   

    lz 的想法属于典型的 js 滥用,根本没有使用 js 的必要!给超链接加上 target="_blank" 就可以了L@_@K
    <a href="http://hi.csdn.net/space-home.html" target="_blank">csdn</a>
      

  5.   

    查了下资料,drag事件确实是拖动事件,但没找到怎么写的
      

  6.   

    div+onmouseup然后把<a>的href属性去掉因为无论怎么拖,总要放开鼠标的
      

  7.   

    稍微来了点兴趣,出于研究目的,试了试。
    为了代码简单,使用了框架。
    仅供参考。不推荐这样干。
    右键的问题,你怕是没办法直接解决了,因为你无法用JS获取用户究竟点了哪个右键菜单。
    除非你自己实现一个JS构建的右键菜单,那你又会碰到非常麻烦的兼容性问题。
    下面的代码实现了一点点简单的拖拽逻辑,部分事件代码看起来多余,去掉试试就会发现会碰到很多兼容性问题。
    还是那句话,干这种吃力不讨好的事情真的没啥必要。
    回去冷静2天你就会觉得这个想法真的没啥好的。
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title></title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/mootools/1.2.4/mootools-yui-compressed.js"></script>
    </head>
    <body>
    <div><a href="http://www.baidu.com" target="_blank">www.baidu.com</a></div>
    <div><a href="http://www.google.cn" target="_blank">www.google.cn</a></div>
    </body>
    </html>
    <script type="text/javascript">
    /*<![CDATA[*/ //获取页面上选中文字的相关信息
    function getSelected() {
    var obj = {};
    if (window.getSelection) {
    // This technique is the most likely to be standardized.
    // getSelection() returns a Selection object, which we do not document.
    obj.text = window.getSelection().toString();
    obj.element = window.getSelection().focusNode.parentNode;
    }else if (document.getSelection) {
    // This is an older, simpler technique that returns a string
    obj.text = document.getSelection();
    obj.element = null;
    }else if (document.selection) {
    // This is the IE-specific technique.
    // We do not document the IE selection property or TextRange objects.
    obj.text = document.selection.createRange().text;
    obj.element = document.selection.createRange().parentElement();
    }
    return obj;
    } window.addEvent('domready',function(){
    var enableDrag = false;
    var enableDragOpen = false;
    var url = null;

    $$('a').addEvents({
    'mousedown':function(event){
    enableDrag = true;
    event.stop();
    },
    'mousemove':function(event){
    if(enableDrag){
    enableDragOpen = true;
    url = this.href;
    }
    enableDrag = false;
    event.stop();
    },
    'mouseup':function(event){
    url = null;
    enableDrag = false;
    enableDragOpen = false;
    event.stop();
    }
    });
    document.addEvents({
    'mousemove':function(event){
    if(enableDragOpen){
    event.stop();
    }
    },
    'mouseup':function(){
    if(enableDragOpen){
    window.open(url);
    }
    url = null;
    enableDrag = false;
    enableDragOpen = false;
    },
    'keydown':function(event){
    if(event.control && event.key == 'v'){
    var selected = getSelected();
    if(selected.element){
    if($(selected.element).get('tag')=='a'){
    window.open(selected.element.href);
    }
    }
    }
    }
    });
    });/*]]>*/
    </script>
      

  8.   

    这个其实就是类似金山词霸的取词划词功能
    Google工具栏 也有这个功能是感应英文单词的
    纯js实现很难 除非用activeX
      

  9.   

    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head><body onmouseup="showSeletedLink()">
    http://www.baidu.com
    <script language="javascript" type="text/javascript">function showSeletedLink()
    {
    var linkText=document.selection.createRange().text;
    window.open(linkText,'','','');
    }
    </script>
    </body>
    </html>
      

  10.   


    您的代码就快满足条件,呵呵真行,不过可能是因为我没说清楚,我的设想是当浏览者选择了“http://www.abc.com ”,它打开的是“http://www.abc.com/123.html ”,因为“http://www.abc.com”这些字符是包含在“http://www.abc.com/123.html ”链接中而您的代码是选择什么字符,就打开什么,再者,您能不能把点击右键就打开网页的功能删除,感激不尽!
      

  11.   

    没成功?我本地可是确保运行成功的,包括IE和FF……
    你没上网?或者没有加载该库?