Reputation:
I am opening a blank window and writing a javascript on the new window to submit a form.
when I execute a line "newWindow.document.write(newwdtxt2);\n\"(3rd line from last) I get an exception and last two lines do not execute. Below mention is my code
function openWindow(url,name,options) {
var aToken = "";
aToken ="2121225434349231132674638921:SUPER.SUPER";
if(aToken=="") {
aToken=document.formEMS.AUTHTOKEN.value; }
var newWindow = window.open("", name);
if (!newWindow) return false;
var newwdtxt = "";
newwdtxt += "<html><head></head>\n";
newwdtxt += "<body>\n";
newwdtxt += "<form name=\"eventForm\" method=\"post\" action="+url+ ">\n";
newwdtxt += "<input type=\"hidden\" name=\"AUTHTOKEN\"";
newwdtxt += "value= '";newwdtxt += aToken+"'/>\n";
newwdtxt += "</form>\n";
newwdtxt += "<scr";
var newwdtxt1 = "";
newwdtxt1 += "ipt type=\"text/javascript\" language=\"javascript\">\n";
newwdtxt1 += "window.onLoad=document.eventForm.submit();\n";
newwdtxt1 += "</scr";
var newwdtxt2 = "";
newwdtxt2 += "ipt>\n";
newwdtxt2 += "</body></html>\n";
newWindow.document.write(newwdtxt);
alert(newwdtxt);
newWindow.document.write(newwdtxt1);
alert(newwdtxt1);
alert(newwdtxt2);
newWindow.document.write(newwdtxt2);
alert('wrote newwdtxt2');
return newWindow; }
Please help me to figure out what is the problem?
Upvotes: 0
Views: 125
Reputation: 30073
var doc = '<html>\ <head>\ </head>\ <body>\ </body>\ </html>';
Upvotes: 1
Reputation: 4395
That will make a syntax exception. Try this instead:
newWindow.document.write(newwdtxt+newwdtxt1+newwdtxt2);
Upvotes: 1
Reputation: 2130
I believe when you do a document.write the browser parses the html you wrote into DOM nodes. In your code you're writing incomplete HTML so when it gets parsed it is giving an error. Try putting the "ipt>" onto the end of 'newwdtxt1' instead of where it is now.
Upvotes: 0