I am calling the following function from a button click to open a new window/tab and display an alert and update a text:
function nWin(p) {
var setStyle = "<style rel='stylesheet'>\
.vTop {\
vertical-align: top;\
}\
<\/style>";
var setScript = "<script>alert('test');<\/script>";
setScript += "<script src='http://code.jquery.com/jquery-1.11.0.min.js'><\/script>";
setScript += "<script>$(function () { $('#sText').html('UPDATED TEST'); });<\/script>";
var w = window.open();
var createBody = $(w.document.body);
var createHead = $(w.document.head);
createBody.html("");
createBody.html(p);
createBody.append("<span id='sText'>THIS IS A TEST</span>");
createHead.html(setStyle);
createHead.append(setScript);
}
When I click the button the alert is shown from the page I click the button from rather than on the window/tab that is created and also the sText
text does not change.
Here is a HTML Source:
How can I resolve it so it works correctly, where the alert is shown in the new window/tab and also the span text is updated.