locked
Open a new tab and redirect RRS feed

  • Question

  • User159480641 posted

    Hi, I'm trying to create an app witch create payment recipies. What I'm trying to to is when the CreateView submit return the IndexView as normal, but at the same time open a new tab with the recipt to be print.

    Thanks for your help!

    I atache an image with what I want to do:

    Tuesday, July 23, 2019 12:22 PM

Answers

  • User753101303 posted

    It might be clearer for users to show the receipt and then navigate from the receipt to the index view.

    If you feel it's better because the receipt view can only contain stuff to be printed you can use @media print rules to show a navbar on screen but to use display:none for this navbar when printing.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 23, 2019 1:58 PM
  • User1520731567 posted

    Hi guillos,

    According to your descriptions,I suggest you could use document.referrer to judge original page,and open new tab with print by javascript,

    for example:

    when you click  submit button in Create View,it will jump to post action:

     [HttpPost]
            public ActionResult Create([Bind(Include = "xxxx,xxx")] Model mod)
            {
                if (ModelState.IsValid)
                {
                    db.xxx.Add(mod);
                    db.SaveChanges();
                    return RedirectToAction("Index");//return Index View
                }
    
                return View(mod);
            }

    in Index view:

    @section scripts
    {
    <script>
    $(function () {
    if (document.referrer.indexOf("Create")>0)//if it redirect by Create View
    {
      var myWindow = window.open('', '', 'width=600,height=600');
      myWindow.document.write("<p>This is 'myWindow'</p>");
    
      myWindow.document.close();
      myWindow.focus();
      myWindow.print();
      myWindow.close();
    }
    })
    </script>
    }

    How it works:

    Best Regards.

    Yuki Tao

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 24, 2019 6:15 AM

All replies

  • User-1038772411 posted

    Hello, guillos

    Please refer below link hope you will get your below link.

    https://stackoverflow.com/questions/14509616/open-mvc-view-in-new-window-from-controller

    Thanks.

    Tuesday, July 23, 2019 1:39 PM
  • User753101303 posted

    It might be clearer for users to show the receipt and then navigate from the receipt to the index view.

    If you feel it's better because the receipt view can only contain stuff to be printed you can use @media print rules to show a navbar on screen but to use display:none for this navbar when printing.

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 23, 2019 1:58 PM
  • User-474980206 posted
    Due to browsers blocking pop up ads, there is not really a way to do what you want. Nowadays you can only open a new window/tab from an anchor or submit button click via the target. This means the original page is unchanged.

    You best best as suggested is a link to open the separate receipt.
    Tuesday, July 23, 2019 2:07 PM
  • User1520731567 posted

    Hi guillos,

    According to your descriptions,I suggest you could use document.referrer to judge original page,and open new tab with print by javascript,

    for example:

    when you click  submit button in Create View,it will jump to post action:

     [HttpPost]
            public ActionResult Create([Bind(Include = "xxxx,xxx")] Model mod)
            {
                if (ModelState.IsValid)
                {
                    db.xxx.Add(mod);
                    db.SaveChanges();
                    return RedirectToAction("Index");//return Index View
                }
    
                return View(mod);
            }

    in Index view:

    @section scripts
    {
    <script>
    $(function () {
    if (document.referrer.indexOf("Create")>0)//if it redirect by Create View
    {
      var myWindow = window.open('', '', 'width=600,height=600');
      myWindow.document.write("<p>This is 'myWindow'</p>");
    
      myWindow.document.close();
      myWindow.focus();
      myWindow.print();
      myWindow.close();
    }
    })
    </script>
    }

    How it works:

    Best Regards.

    Yuki Tao

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Wednesday, July 24, 2019 6:15 AM