在不使用<a>( open link in new tab/window not working)

时间:2017-09-19 21:23:17

标签: javascript jquery html css3 javascript-events

I have couple of button on the page. Each one, when clicked, redirects to a different page. There are 10-12 such buttons on the page. Whenever we click on this button, the 'form' respective to that button is submitted and that is how we are redirected to a new page.
I am using an image for these buttons. but when I do right click, instead of showing "open link in new tab", it shows "open image in new tab". because of few other design problems I can not wrap image into anchor tag.

Is there any way to open the regular right click menu, and when we click "open link in new tab", it submits the form and displays that in new tab? This is what I want to do.

$.each(EventArray, function(index,value){
    $('.'+value).on('click', function(e){
        //if redirect button is clicked, submit the form
        if($(e.target).closest('img.btn-redirect').length !== 0){
            $('#form-'+value).submit();
        }
    })

    $('.'+value).on('contextmenu', function(ev){
        //if right click 
        if($(ev.target).closest('img.btn-redirect').length !== 0 
        {
            //open the regular right click menu
           //on selection of "open link in new tab"
            $('#form-'+value).submit();
        }
    })
 })

0 个答案:

没有答案