Guide on how to create a new tab in a table by using the context menu

I have implemented a datatable to display data and I'm using a context menu for navigation to another page. However, I encountered an issue where clicking on the context menu tab opens the new window in the same tab instead of opening it in a new tab as intended. Below is the code snippet that's causing this issue:

<script type="text/javascript" class="showcase">
            $(function() {
                var selectedVal;
                $.contextMenu({
                    selector : '.context-menu-one',
                    callback : function(key, options) {
                        var row = options.$trigger;
                        var newUrl = key;
                        
                        // Context menu actions based on selected key
                        if (key === 'calllist.do' || key === 'travel' ||
                            key === 'call_usage' || key === 'network_analysis' ||
                            key === 'location_analysis.do' || key === 'location_tracker.do') {
                            var rows = row.find("td").eq(3).html();
                            actionUrl = '?' + 'a_no=' + rows.toLocaleString();
                        } else if (key === 'personal' || key === 'newsim.do' ||
                                   key === 'analyzecallingno' || key === 'simdensity.do') {
                            var rows = row.find("td").eq(1).html();
                            actionUrl = '?' + 'a_no=' + rows.toLocaleString();
                        }
                        
                        document.forms[0].action = newUrl + actionUrl;
                        document.forms[0].submit();
                    },
                    items : {
                        "analyzecallingno" : { name : "Analyze Calling Number" },
                        "travel": { name : "Analyze Caller Tower" },
                        "network_analysis" : { name : "Social Network Analysis" },
                        "call_usage" : { name : "Call Analysis Summary" },
                        "location_tracker.do" : { name : "Location Tracking" },
                        "personal" : { name : "Caller Personal Details" }
                    }
                });
            });
        </script>

        <table class="tableData context-menu-one" id="tableData"
            style="overflow-x: scroll">
            <thead>
                <tr style="font-size: 14px;">
                    <th align="left">CALLTYPE</th>
                    <th align="left">CALLER</th>
                    <th align="left">CALLEE</th>
                    <th align="left">DURATION</th>
                    <th align="left">START DATE</th>
                    <th align="left">END DATE</th>
                    <th align="left">FROM LOC</th>
                    <th align="left">TO LOC</th>
                    <th align="left">IMEI</th>
                    <th align="left">IMSI</th>
                </tr>
            </thead>
            <tbody>
                <c:forEach items="${searchpage}" var="listofvalues">
                    <tr class="context-menu-one notfirst" style="font-size: 12px;">
                        <td align="left"><c:out value="${listofvalues.call_type}" /></td>
                        <td align="left"><c:out value="${listofvalues.a_no}" /></td>
                        <td align="left"><c:out value="${listofvalues.b_no}" /></td>
                        <td align="left"><c:out value="${listofvalues.call_duration}" /></td>
                        <td align="left"><c:out value="${listofvalues.start_day}" /></td>
                        <td align="left"><c:out value="${listofvalues.end_day}" /></td>
                        <td align="left"><c:out value="${listofvalues.a_home_circle}" /></td>
                        <td align="left"><c:out value="${listofvalues.a_rome_circle}" /></td>
                        <td align="left"><c:out value="${listofvalues.a_imei}" /></td>
                        <td align="left"><c:out value="${listofvalues.a_imsi}" /></td>
                    </tr>
                </c:forEach>
            </tbody>
        </table>
    </div>
</div>

Answer №1

If you're looking for an alternative, consider using something like

$("form:first").attr('target', '_blank').submit();
in place of
document.forms[0].action = newUrl + actionUrl;
.

By the way, don't overlook setting your action URL:

$("form:first").attr({
                      'target':'_blank',
                      'action':newUrl + actionUrl
                    }).submit();

An additional option is to utilize $( "form" ).first().attr.....

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

The Firebase function for updating the counter is experiencing delays

My real-time database has a counter variable that increments with each function call. However, if multiple users trigger the function simultaneously when the counter is at 1, they both get the same value for the counter (1) instead of it incrementing to 3 ...

What is the best way to save a reference using a POST API in NodeJs?

Currently utilizing the express.js framework for building a MERN stack application. This is my first endeavor into creating a full-stack JavaScript app, so a lot of the functions are new to me. I am in the process of sending a new post to a topic and updat ...

I am facing difficulties with the header in CSS as it is not resizing properly

I'm having trouble getting my mobile-first design to work properly because the header doesn't resize in mobile view. I'm satisfied with how it looks in full-screen, but I haven't been able to make any media queries work. You can downloa ...

Clicking on a jQuery dropdown will focus the input box

I am working on a jQuery dropdown menu that contains an input box. My goal is to automatically focus on the input box when the dropdown is clicked. Here is the HTML code for the textbox: <input type="text" name="username" id="username"/> And here ...

Assign the source property of the Handsontable dropdown option to match the related data value

I received a dynamic data array through an ajax call: data=[ // values are subject to change ['Alex', '16', ['2024-01-01,50000', '2024-03-01,20000', '2024-05-01,30000']], ['Bob&apos ...

Jquery fails to display errors or provide validation feedback

I have been struggling to implement form validation on my website without using jQuery validate. Unfortunately, the code I have written is not functioning properly and is causing some CSS issues in my local environment. My main objective is to validate fo ...

Issue with Material-UI DataGrid Component: Unable to access property 'length' as it is undefined

I need to display my JavaScript Object Data in a table format with pagination and sorting capabilities. I have chosen the DataGrid component from Material UI, but I am encountering some errors. Below is the code snippet: import React from 'react&apos ...

The new additional formatting features I added to Bootstrap are causing issues with my layout

Originally, my code featured an image positioned on the right-hand side before I separated each H1 element into separate sections. Click here to see a picture of the page before the edit After separating the elements into divs, the image now sits on the t ...

Responsive Menu Design with Bootstrap 3.x

In my web design, I have utilized Bootstrap 3.3.7 and it works flawlessly on mobile, desktop, and laptop devices. However, I have noticed that the three-bar menu does not appear on tablets when using the default Bootstrap navbar: <nav class="navbar nav ...

Footer sticking issues, out of place

My multipage website project is coming together, but I'm facing some issues with the footer. While the navbar is behaving as expected on all pages, the footer seems to have a mind of its own. It's inconsistently positioned across different pages, ...

Restrict the maximum and minimum time that can be entered in an HTML input

I've implemented a basic code feature that allows users to input minutes and seconds on my React website. <div> <span> <input defaultValue="0" maxlength="2"/> </span> <span>m</span> <spa ...

Do not apply styling to a particular page in CSS and HTML

Utilize the teachable.com platform and take advantage of their code Snippets feature (refer to attached photo #1) https://i.stack.imgur.com/dW1lB.png I inserted the following code: div { direction: rtl; } To modify the website's direction to be ...

Displaying a table in Chrome/Firefox with a mouseover feature

Hovering over the rows of this table triggers a display of descriptions. html: <tr title="{{transaction.submissionLog}}" class="mastertooltip">... JavaScript: $('.masterTooltip').hover(function(){ // Hover functionality ...

What is the best approach for incorporating sub-navigation within a page popup in a Next.js project?

In the midst of my Next.js project, there is a requirement to showcase a chat popup consisting of multiple sub-pages like user registration, conversation page, and more. Hence, seamless navigation inside this popup is necessary. The idea is not to alter th ...

Bootstrap causing problem with image cropping

Currently, I am encountering a problem with the sorting of images using a bootstrap blade.php file. I aim to neatly organize the images on my website, but it appears that some images are partially cropped out, resulting in an unattractive look. My goal is ...

Guide on decrypting a file encrypted with C# using Node JS

I currently have encrypted files in C# using DES and PKCS7 encryption. My objective is to decrypt these files in Node JS. The decryption code in C# that I am using appears like this: public string SSFile_Reader( string fileToDecrypt ) { DESCryptoService ...

What are the steps to implement the jQuery slide menu effect on a website?

When visiting the website , you may notice a symbol positioned in the top left corner of the site. By clicking on this symbol, a sleek div will slide out. How can this type of animation be achieved through javascript or jquery? ...

Show the output of a MySQL query on a modal, alert, or popup box within a webpage initiated by a search box, with the option to close the

Having worked in IT for 16 years, I am new to coding and seeking help on displaying search results from an input HTML box. I want the data from a MySQL database to be displayed in a modal, alert, or popup box with a closing "X" button. This database only c ...

Modify the appearance of certain text within an input field

I need some help adding style to specific text within an input field. For example, if the user types in "Hello world" and the special text is "world" I want to achieve this result: https://i.sstatic.net/Ozd6n.png This is what my HTML code looks like: & ...

Oops! Looks like there's an issue with the route configuration for ''. Make sure to include one of the following: component, redirectTo, children, or loadChildren in order to validate the

I've been facing an issue while setting up a project with angular routing. The project is only displaying the contents of index.html and not app.component.html. Upon inspection, I noticed that the body tag just has <app-root></app-root> in ...