简体   繁体   中英

Javascript open in new tab by using json

Javascript Code:

   <script type="text/javascript">
    function MusteriBilgileriKaydet2() {
        var veri = {

            AnaOzelDurumId: AnaOzelDurumId.GetValue(),
            AnaİlgiliPersonelId: AnaİlgiliPersonelId.GetValue(),
        };

        if (veri.MusteriAdiTextBox1.trim() == "" || veri.MusteriAdiTextBox1 == undefined || veri.MusteriAdiTextBox1 == null) {
            $("#showwarning222").html('<img src="/Image/warning.png" title="Müşteri Adı Giriniz!">').show();
        }
        else {
            LoadingPanel.Show();
            $.ajax({
                url: "/Home/GenelMusterilerGridView2",
                type: "POST",
                dataType: "json",
                contentType: 'application/json',
                data: JSON.stringify(veri),
                success: function (mydata) {
                    if (mydata.error6 == true) { // Error
                        LoadingPanel.Hide();
                        alert("Müşteri Adı Mevcut");
                        $("#showwarning222").html('<img src="/Image/warning.png">').hide();
                    }
                    else { // Success
                        $("#MusterilerGetir").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 GenelMusterilerGridView2(MyModel model)
    {
    var stringView = RenderRazorViewToString("MerkezPartial", ModelleriGetir());
                return Json(stringView, JsonRequestBehavior.AllowGet);
            }
            else
            {
                return Json(new { error6 = true, JsonRequestBehavior.AllowGet });
            }
        }
        return null;
    }

My all codes works well .

I only want to open in new tab page .

So How can i open in new tab in browser after i post data to my controller ?

Any help will be greatly appreciated.

Thanks.

you can add to your html <a href tag a target that looks like this.

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

OR you can in your javascript code add

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

Now this should be working fine but just because some clients prevent pop-ups then you could add this to your html tag too.

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

Hope this will work for you

Cheers!

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM