Kumar
Kumar

Reputation: 39

javascript - My link cannot open another link

When i click on a link (a href), only background loader appears. But the defined link is not opening, the screen strucks in the loader screen. In this screen i cant access any function. I have been trying this for weeks, but no positive results. Please help me to find the error in the added codings

$(document).ready(function() {
    var loading = $('<div>').prop('id', 'loading');
    loading.html('<div id="stretch"></div><img src="assets/img/ring.gif" style="repeat:no-repeat;" /> Loading...');

    //FOR TESTING         
    //alert(  loading.text() ); //FOR TESTING ONLY!!!
    $("#cmd").click(function() {
        loading.appendTo('body');

        var event = $(document).click(function(e) {
            e.stopPropagation();
            e.preventDefault();
            e.stopImmediatePropagation();
        });

        // disable right  click
        $(document).bind('contextmenu', function(e) {
            e.stopPropagation();
            e.preventDefault();
            e.stopImmediatePropagation();
        });
    });
});;
#loading {
    background-color: white;
    background-color: rgba(1, 1, 1, 0.7);
    bottom: 0;
    left: 0;
    position: fixed;
    right: 0;
    text-align: center;
    top: 0;
}

#loading * {
    vertical-align: middle;
}

#stretch {
    display: inline-block;
    height: 100%;
}
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<li><a  href="http://www.google.com/"  id="cmd" ><i class="glyphicon glyphicon-tags"></i>Application</a></li>

.

Upvotes: 0

Views: 79

Answers (1)

MortenMoulder
MortenMoulder

Reputation: 6646

Well of course it's not doing anything, when you stop the default event from triggering (clicking).

e.preventDefault();

This prevents the default action from happening. However, you are going to hit issues when you load 3rd party websites using Javascript.

Upvotes: 1

Related Questions