Skip to main content

How to Open URL in New Tab using AJAX

How to Open URL in New Tab using AJAX

Today, We want to share with you How to Open URL in New Tab using AJAX.
In this post we will show you , hear for How to open AJAX response in new window we will give you demo and example for implement.In this post, we will learn about Open link in new tab within Ajax callback with an example.

My Paka Knowledgeable Ideas, Tips and Tricks, Useful Content, Jobs, Technology, Earn Money, gmail creation, skype, yahoo and more useful things.

In AJAX How can I open a link in a new tab?, Open new window when target=”_blank”

<Link to="/about" target="_blank">About Pakainfo.com</Link>

AJAX Overview with Features

There are the Following the List of Features For AJAX Pure JavaScript Latest Frameworks.

  • Speed Reduce
  • Better Interactivity
  • Easy Navigation
  • Minimal Data Transfer
  • Compact
  • Interaction
  • XMLHttpRequest
  • Asynchronous calls
  • Form Validation
  • Bandwidth Usage
Also Read :  Ajax Upload Multiple Images without form submit

AJAX redirect to a new tab

<a href="/">pakainfo</a>
<a href="/" target="_blank">InfinityKnow</a>

//Ajax Call
$('a').on('click', function(event){
  event.preventDefault();
  event.stopPropagation();
  var newtabs = $(this).attr('target');
  var URL = $(this).attr('href');

  setTimeout(function(event){

    if ( newtabs === undefined ) {
      alert('How to Open URL in New Tab using AJAX');
      window.location.href = URL;
    } else if ( newtabs === '_blank' ) {
 
      alert('How to Open URL in New Tab using AJAX');
      window.open(URL, '_blank');

    } else {
      // here simple Default redirect?
    }

  }, 500);

});

Demo New Tab using AJAX

AJAX Redirects

$(document).ready(function(){ 
    jQuery.ajax({ 
        type: "GET", 
        url: "api/data/paka.htm", 
        dataType:"json", 
        data:"userId=SampleUser", 
        success:function(results){ 
            if (results.redirect) {
                window.location.href = results.redirect;
            }
            else {
                // some here Ajax Process the expected Data results...
            }
        }, 
     error: function(xhr, textStatus, errorThrown) { 
            alert('sorry, Error!  Status = ' + xhr.status); 
         } 

    }); 
}); 

AJAX Redirect To External Domains

  $.ajax({
        url: $('#dataReq').attr("action"),
        data: $('#dataReq').serialize(),
        type: $('#dataReq').attr("method"),
        success: function (resp) {
            location.href = "https://pakainfo.com/api/"; // Ajax redirect
        },
        error: function(e) {
            alert('Error: '+e);
        } 

jQuery 15 Powerful Tips and Tricks for Developers and Web Designer

Read : AJAX

Also Read :  How to Open URL in New Tab using CodeIgniter

Summary

You can also read about AngularJS, ASP.NET, VueJs, PHP.

I hope you get an idea about AJAX for redirecting to external domain.
I would like to have feedback on my Pakainfo.com blog.
Your valuable feedback, question, or comments about this article are always welcome.
If you enjoyed and liked this post, don’t forget to share.

Gondaliya Jaydeep

Hi, I’m Jaydeep Gondaliya, PHP developer.Pakainfo.com is the most popular Programming & Web Development blog. Our mission is to provide the best online resources on programming and web development.Any visitors of this site are free to browse our tutorials, live demos, Examples and download scripts.If you have a project that you want to get started, launch quickly, contact me. Email : [email protected]