当点击超链接jquery应该工作,页面不应导航 - jquery

时间:2011-07-11 10:32:06

标签: jquery

我正在显示一个文本,例如让我们将文本视为“SOF”。

当我点击“SOF”文字时,我会在iframe中显示我网站中的特定网站。

这个案子工作得很好......

但我的问题是,当我点击“SOF”文本iframe正在加载以及页面也完全导航到同一页面。这不应该发生。我在这里给了我的代码。什么是防止重定向整个网站的方法。

编辑:

此网址正常:http://www.oercommons.org/browse/collection/free-ed-gov

此网址无效:http://www.merlot.org/merlot/viewMaterial.htm?id=79516

可能是什么问题..: - (

注意:我知道在iframe中显示网站不需要jquery。但在我的情况下,有时我会显示html,pdf等...所以我需要使用jquery。 : - )

var xhr = null;
    //by default set the element properties
    var preview_on = true;

    Drupal.behaviors.previewOverview = function(context) {
      //show preview on mouse over
      $('.links a').click(function(e) {
        e.preventDefault();
        if (xhr && xhr.readyState != 4) {
          //if previous ajax is working then cancel it
          xhr.abort();
          //$('#right-sidebar-right').html('Preview Panel.');
        }
            if (preview_on) {
                curLink = this;
                targetLink = this.href;        
                data = '<div><a href='+ targetLink +' target="_blank">View Original Page</a></div>' + '<iframe src="' + targetLink + '" width="100%" height="500px"></iframe>';
                // To display the data in selected area.
                $('#right-sidebar-right').html(data);
            }
        } else {
          $('#right-sidebar-right').html('Turn on preview mode to view.');
        }
    });

1 个答案:

答案 0 :(得分:0)

或者,你也可以做..

<a href="http://www.google.com" >google</a>


$('a').click(function(e){
    alert("do something");
    e.preventDefault();
});

尝试调整示例here ..