Use JSON to initiate opening a new tab in JavaScript code

Javascript Code:

   <script type="text/javascript">
    function SaveCustomerInformation() {
        var data = {

            SpecialStatusId: AnaOzelDurumId.GetValue(),
            ContactPersonId: AnaÄ°lgiliPersonelId.GetValue(),
        };

        if (data.CustomerNameTextBox1.trim() == "" || data.CustomerNameTextBox1 == undefined || data.CustomerNameTextBox1 == null) {
            $("#showwarning222").html('<img src="/Image/warning.png" title="Please enter a Customer Name!">').show();
        }
        else {
            LoadingPanel.Show();
            $.ajax({
                url: "/Home/GeneralCustomersGridView2",
                type: "POST",
                dataType: "json",
                contentType: 'application/json',
                data: JSON.stringify(data),
                success: function (mydata) {
                    if (mydata.error6 == true) { // Error
                        LoadingPanel.Hide();
                        alert("Customer Name already exists");
                        $("#showwarning222").html('<img src="/Image/warning.png">').hide();
                    }
                    else { // Success
                        $("#CustomersDisplay").html(mydata);
                        LoadingPanel.Hide();
                        $("#showwarning222").html('<img src="/Image/warning.png">').hide();
                    }
                },
                error: function () {
                    LoadingPanel.Hide();
                    $("#showwarning222").html('<img src="/Image/warning.png">').hide();
                }
            });
            return false;
        }
    }

</script>

My Controller:

    public ActionResult GeneralCustomersGridView2(MyModel model)
    {
        var stringView = RenderRazorViewToString("CenterPartial", GetModels());
        return Json(stringView, JsonRequestBehavior.AllowGet);
        }
        else
        {
            return Json(new { error6 = true, JsonRequestBehavior.AllowGet });
        }
        return null;
    }

All of my code is functioning perfectly.

I simply need to open the result in a new tab.

How can I achieve this after submitting data to my controller?

Any assistance on this matter would be highly appreciated.

Thank you.

Answer â„–1

To enhance your HTML <a href tag, consider including a target attribute as shown below.

<a href="yourURL" id="someID" target="_blank">Link name or text</a>

If you prefer to modify your JavaScript code, you can do the following:

function OpenNewTab(url){ 
 var newTab = window.open(url, '_blank');
 newTab.focus(); 
 }

This method should work smoothly, but keep in mind that some clients may block pop-ups. In such cases, you can add this snippet to your HTML tag as well.

<div onClick="OpenNewTab();">your link name</div>

We hope these solutions prove useful for your needs. Good luck!

Cheers!

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

RectAreaLight causing low frame rates in three.js

In my futuristic setting, I am incorporating RectAreaLights to mimic strip lights. However, I am encountering a performance issue as my frames per second (fps) drop significantly when using these lights, typically not exceeding 20 or 30. On the other hand, ...

Can we access local storage within the middleware of an SSR Nuxt application?

My Nuxt app includes this middleware function: middleware(context) { const token = context.route.query.token; if (!token) { const result = await context.$api.campaignNewShare.createNewShare(); context.redirect({'name': &a ...

Unexpected error 500 (Internal Server Error) occurred due to BadMethodCallException

Using Vue 2.0 and Laravel 5.4, I am working on creating a matching system that includes a dynamic Vue component. For example, when someone likes another person, it should immediately show that the like has been sent or if the like is mutual, it should indi ...

JQuery receives an enchanting response from the magic line

I could really use some assistance with this problem. I've managed to make some progress but now I'm stuck! Admittedly, my JQuery skills are not that great! Currently, I have a magic line set up where the .slide functionality is triggered by cli ...

When conducting a click + drag mouse action, Internet Explorer may experience freezing. What steps can be taken to identify the root cause of this issue

Currently, I am in the process of developing a JavaScript application designed for generating simple diagrams. However, I have encountered some performance issues specifically in Internet Explorer version 8. This application allows users to draw lines on ...

Developing an Android application involves creating a JSON object from a string in order to effectively manage

I am working on creating a JSON object to handle errors from network calls. The way I am currently parsing the error is by using the following code: {error:errorMessage} Here are my attempts so far: String error = "{\"error\":\""+ e.getM ...

Tips for dynamically populating an HTML table with data from a JSON array using JQuery

I have generated an HTML table <table id="top_five_table"> <tr> <td> </th> <th>URL</th> <th width="90">Total Hits</th> <th width="380">Percentage of all Hits</th> </tr> <tr> ...

Countless unsuccessful connection attempts on Node.js and socket.io

Good day awesome community at SO! I've been struggling to resolve this issue, and now I'm turning to you for some guidance because I can't seem to figure it out on my own. I have a node.js server that serves an index.html through express, an ...

Connecting the JSON response from AJAX Autocomplete to a designated webpage or URL

I'm attempting to associate each Ajax Autocomplete result with a designated URL ("landing Page"). URL: www.aebli.com, search field located in the upper right corner, try entering "h" or "ho" Ajax Code for the Search Box: <script type="text/javasc ...

Is there a way to extract the MIME type from a base64 string?

My base64 String appears as "UklGRkAdEQBXQVZFZm10IBIAAAABAAEAg...". I am attempting to download this file using my browser. Therefore, I convert it to a blob with the following function: b65toBlob: function(b64Data, sliceSize = 512) { ...

Deciphering deeply nested JSON data using Python and Pandas

My goal is to extract information from a JSON response and convert it into a dataframe for export to a .csv file. The JSON response structure includes the following fields: { "count":2, "next":null, "previous":null, "results":[ { ...

Accessing JSON data in SQLiteHere are ways to access

I am dealing with a sqlite database that contains a column named data, which stores a json string. I am trying to extract specific values from this json string but have been unsuccessful so far. How can I achieve this? JSON string in the SQL DB: {"lang": ...

Combining the contents of two JSON Arrays to form a JSONObject in Java

My JSON Arrays are structured like this: [6, 7, 8, 9, 10, 11] [122402538, 12240345, 122496, 122617, 1227473, 1228495] The goal is to merge each Long value with another while preserving its index, resulting in a structure like: [{"id": 6, "timestamp" ...

Running the command "npm install [package]" does not automatically update the package.json file

I'm currently utilizing Laravel and experimenting with angular-ui-sortable and angular-utils-pagination. I have successfully installed them using npm, however, I am facing difficulties in updating the package.json file for angular-utils-pagination. ...

Transforming a string into a dictionary or JSON-like format

I'm struggling to transform a string in JSON format into a JSON/dictionary object. The data I have looks like this: {"key1":"value1","key2":[{"key2.1":"value2.1"},{"key2.2":"value2.2"}]} When I run type on the variable, it shows that it is of type s ...

What is the best way to filter a JSON string in Python using an array of keys?

I have the following JSON string: a={"44":[ { "16":{ "unitData":[ ], "unitHeader":{ "t9u":"P3P34", "sum":"807", } } }, { "16":{ "unitData":[ ...

Pressing the submit button in the Material UI table clears all selected checkboxes

Take a look at this code snippet: https://jsfiddle.net/aewhatley/Lkuaeqdr/1/. My objective is to construct a table with a submit button utilizing Material-UI components. const { Table, TableHeader, TableHeaderColumn, TableBody, TableRow, Table ...

JavaScript - Swapping out element in object array

I'm struggling to develop a function that can normalize features within a dataset, ensuring they fall between 0 and 1. My goal is to iterate through all the features and update their values as I perform normalization. While the normalization process i ...

User should clear the cache to accommodate the latest release

After each release, users are required to manually clear their cache in order for the new code to be applied. Is there a feature or method that could automate this process? ...

Activating the spinner functionality using JavaScript

Having trouble activating the spin button with JavaScript for my spinner. Any ideas on how to make it work? <!DOCTYPE html> <html lang="en"> <head> <title>My Spinner</title> <link rel="stylesheet" ...