• Skip to primary navigation
  • Skip to main content
  • Skip to primary sidebar
seegatesite header

Seegatesite.com

Seegatesite.com - Programming Tutorial , Sharing , How and Learn Together

  • TOOLS
    • Bootstrap Navbar Online Generator
    • Customize Sidebar Menu Bootstrap 3
    • Bootstrap Demo
  • ADVERTISE
  • CATEGORIES
    • Android
    • Blogging Tips
    • Database
    • CSS
    • Info Gadget
    • Javascript
    • Linux
    • PHP
    • Various
    • WordPress
  • Q&A
  • PHP
  • JAVASCRIPT
  • JQUERY
  • ANGULAR
  • WORDPRESS
  • SEO
  • REACT
🏠 » Javascript » Trick To Redirect New Window Or Tab With Post Method On Angular 5

Trick To Redirect New Window Or Tab With Post Method On Angular 5

By Sigit Prasetya Nugroho ∙ June 25, 2018 ∙ Javascript ∙ 4 Comments

Share : TwitterFacebookTelegramWhatsapp

I have not found a suitable library to redirect a page to a new tab using the post method on angular 2, 4, 5 and latest. I Using native javascript makes a simple service, so the app can redirect to a new page using the post method. Who knows any of you who need this script. Follow the tutorial open new tab with post method in angular below.

Trick To Redirect New Window Or Tab With Post Method On Angular 5 Min

Table of Contents

  • 1 Create a simple plugin to redirect a new window with the post angular method
    • 1.1 So my short tutorial Redirect New Window Or Tab With Post Method On Angular 5, hopefully useful

Create a simple plugin to redirect a new window with the post angular method

1. Create a new service named redirect.service.ts or use the following angular cli service

1
ng generate service redirect

2. open redirect.service.ts and fill in the following script

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
import { Injectable } from '@angular/core';
 
@Injectable()
export class RedirectService {
  constructor() { }
  post(obj,url) {
    var mapForm = document.createElement("form");
    mapForm.target = "_blank";
    mapForm.method = "POST"; // or "post" if appropriate
    mapForm.action = url;
    Object.keys(obj).forEach(function(param){
      var mapInput = document.createElement("input");
      mapInput.type = "hidden";
      mapInput.name = param;
      mapInput.setAttribute("value", obj[param]);
      mapForm.appendChild(mapInput);
  });
  document.body.appendChild(mapForm);
  mapForm.submit();
}
 
}

3. Add the service you created earlier into app.module.ts

1
2
3
4
5
6
7
8
9
10
11
12
import { RedirectService } from './redirect.service';
 
@NgModule({
  declarations: [
   ...........
  ],
  imports: [
   ........
  ],
  providers: [RedirectService],
  bootstrap: [AppComponent]
})

4. To use the redirect plugin, follow these steps

1
2
3
4
5
6
7
8
9
10
11
12
import { RedirectService } from './redirect.service';
 
@Component({
  selector: 'app-root',
  templateUrl: './app-root.html',
  styleUrls: ['./app-root.scss']
})
export class AppComponent {
  constructor(
private opentab: RedirectService,
  ){  }
}

1
2
let param = {id_trx:res.param.newidtrx};
this.opentab.post(param,"http://192.168.1.20/laporan_sila/nota_tanda_terima.php");

Another article : Angular 4 Tutorial For Beginner With Simple App Project

So my short tutorial Redirect New Window Or Tab With Post Method On Angular 5, hopefully useful

Another Javascript Related Post :

  • React-Table Not Updating or Refreshing Data, The Solution ?
  • How To Custom React Datepicker In Bootstrap
  • Tutorial Create Simple POS Using ReactJS And Laravel Lumen Part 1
  • Adept Using Datatables Plugin In 10 Minutes For Beginners (Tutorial)
  • The Using Of Reactstrap And React-Table, Suitable For Beginners
  • Tutorial Create Simple Block UI Using React JS

Avatar for Sigit Prasetya Nugroho

About Sigit Prasetya Nugroho

This site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.

Reader Interactions

Comments

  1. Avatar for leoleo says

    October 31, 2018 at 8:34 am

    HI, The Safari browser is not working ?
    DO you have any solution, please?

    Reply
  2. Avatar for DivakarDivakar says

    December 10, 2018 at 11:47 am

    I’m looking forward for this code and ill try to work on it

    Reply
  3. Avatar for Yousuf ZamanYousuf Zaman says

    December 29, 2018 at 7:39 pm

    Thanks a lot for your nice trick to bypass the redirection relation issue to any external target.
    It worked for me, but needed to do more test.
    Thanks again.

    Reply
  4. Avatar for MduduziMduduzi says

    July 31, 2020 at 7:47 am

    Hi Sigit Prasetya Nugroho,

    Thanks for the great work on this. I had been working on payfast integration for more than a week, you site has helped me deeply. thanks so much

    Reply

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

Time limit is exhausted. Please reload CAPTCHA.

This site uses Akismet to reduce spam. Learn how your comment data is processed.

Primary Sidebar

Welcome to my Home,

Avatar for MduduziThis site is a personal Blog of Sigit Prasetya Nugroho, a Desktop developer and freelance web developer working in PHP, MySQL, WordPress.



Popular Articles

Checked checkbox AdminLTE Bootstrap in Jquery

November 4, 2014 By Sigit Prasetya Nugroho 7 Comments

Simple create date format validation with jqueryUI

December 21, 2014 By Sigit Prasetya Nugroho Leave a Comment

Create Simple Progress Bar for Fake Online Generator with Jquery

January 10, 2015 By Sigit Prasetya Nugroho Leave a Comment

22+ Coolest Free Jquery Plugin For Premium Theme

October 3, 2015 By Sigit Prasetya Nugroho Leave a Comment

Easy Build Your Anti Copy Paste Plugin

October 6, 2015 By Sigit Prasetya Nugroho Leave a Comment

Popular Tags

adminlte (15) adsense (13) adsense tips (4) affiliate amazon (13) amazon (12) Android (8) angular (16) angular 4 (12) angular 5 (4) asin grabber (3) Bootstrap (27) codeigniter (5) create wordpress theme (5) crud (8) css (6) free wordpress theme (7) google adsense (4) imacros (4) increase traffic (6) jquery (34) laravel (10) laravel 5 (5) learn android (5) lumen api (4) modal dialog (5) mysql (6) nodeJs (4) optimize seo (4) pdo (6) php (30) plugin (53) pos (8) Publisher Tips (5) react (6) Reactjs (9) SEO (37) theme (17) tutorial angular (5) tutorial angular 4 (6) tutorial javascript (10) tutorial javascript beginners (4) twitter (3) wordpress (18) wordpress plugin (13) XMLRPC (5)




  • About
  • Contact Us
  • Disclaimer
  • Privacy Policy
  • Terms and Conditions

©2022 Seegatesite.com