how to open new tab and insert content in it using javascript?


How can I open a new tab using javascript or jquery and insert new dynamic content in it? Bypassing the pop-up issue also, as I need to show a .pdf file in new window, but you can show me the code of opening and showing HTML in it, I will handle the pdf part.

Thanks


Asked by:- pika
2
: 2994 At:- 7/7/2017 1:07:21 PM
javascript jquery open-new-tab html







1 Answers
profileImage Answered by:- jaya

I have done similar work in the past, you need to do two steps in it.

  1. Open another tab using window.open using target as _blank
  2. Call html/pdf url in it

In this way you will be able to bypass pop-up message of browser also, so your code can be

//remember this button click should be by user, otherwise, you will get pop-up 
 $('.button').click(function (e) {

//open new blank tab 
authWindow = window.open('about:blank', '_blank');

//place your html/pdf url in it
authWindow.location.replace('/pdfview/111/view'); // here '/pdfview/111/view' is url to fetch data for window

});

Please, do remember , the above button click should be by user otherwise you will get browser pop-up message

2
At:- 7/7/2017 3:12:36 PM
good answer, it is working for me, as needed. 0
By : vikas_jk - at :- 8/17/2017 10:59:03 AM






Login/Register to answer
Or
Register directly by posting answer/details

Full Name *

Email *




By posting your answer you agree on privacy policy & terms of use