Ok, I wrote my own weblog and I'm working on the web interface for
adding/editing my posts. I decided to add a little preview button...when
the button is clicked it is suppose to open a pop-up window. I wrote the
whole preview function in javascript so that I don't have to reload the
page to see a preview.
Here is the code I wrote that doesn't work at all:
Code:
function generate_previe w() {
var newWin =
window.open('/weblog/pop_up.html','P review','width= 650,height=400' );
var previewText = document.forms[0].logtext.value; var previewTitle =
document.forms[0].title.value; var previewIcon = document.previe w.src;
var insertPoint_Tex t = newWin.document .getElementById ('pre'); var
content_Text = newWin.document .createTextNode (previewText);
insertPoint_Tex t.appendChild(c ontent_Text);
var insertPoint_Tit le = newWin.document .getElementById ('title'); var
content_Title = newWin.document .createTextNode (previewTitle);
insertPoint_Tit le.appendChild( content_Title);
var insertPoint_Ico n = newWin.document .getElementById ('icon');
insertPoint_Ico n.src = previewIcon;
}
And here is the code that works flawlessly to generate the preview:
Code:
function generate_previe w() {
var newWin =
window.open('/weblog/pop_up.html','P review','width= 650,height=400' );
newWin2=window. open();
newWin2.close() ;
var previewText = document.forms[0].logtext.value; var previewTitle =
document.forms[0].title.value; var previewIcon = document.previe w.src;
var insertPoint_Tex t = newWin.document .getElementById ('pre'); var
content_Text = newWin.document .createTextNode (previewText);
insertPoint_Tex t.appendChild(c ontent_Text);
var insertPoint_Tit le = newWin.document .getElementById ('title'); var
content_Title = newWin.document .createTextNode (previewTitle);
insertPoint_Tit le.appendChild( content_Title);
var insertPoint_Ico n = newWin.document .getElementById ('icon');
insertPoint_Ico n.src = previewIcon;
}
It absolutely will not work unless I add these two lines:
Code:
newWin2=window. open();
newWin2.close() ;
It's really weird and I don't know how to fix the problem without opening
another window other than the one that I'm generating the preview in. I'm
not a programmer and I'm not that great with javascript, so if a
javascript guru could point me in the right direction I would really
appreciate it.
adding/editing my posts. I decided to add a little preview button...when
the button is clicked it is suppose to open a pop-up window. I wrote the
whole preview function in javascript so that I don't have to reload the
page to see a preview.
Here is the code I wrote that doesn't work at all:
Code:
function generate_previe w() {
var newWin =
window.open('/weblog/pop_up.html','P review','width= 650,height=400' );
var previewText = document.forms[0].logtext.value; var previewTitle =
document.forms[0].title.value; var previewIcon = document.previe w.src;
var insertPoint_Tex t = newWin.document .getElementById ('pre'); var
content_Text = newWin.document .createTextNode (previewText);
insertPoint_Tex t.appendChild(c ontent_Text);
var insertPoint_Tit le = newWin.document .getElementById ('title'); var
content_Title = newWin.document .createTextNode (previewTitle);
insertPoint_Tit le.appendChild( content_Title);
var insertPoint_Ico n = newWin.document .getElementById ('icon');
insertPoint_Ico n.src = previewIcon;
}
And here is the code that works flawlessly to generate the preview:
Code:
function generate_previe w() {
var newWin =
window.open('/weblog/pop_up.html','P review','width= 650,height=400' );
newWin2=window. open();
newWin2.close() ;
var previewText = document.forms[0].logtext.value; var previewTitle =
document.forms[0].title.value; var previewIcon = document.previe w.src;
var insertPoint_Tex t = newWin.document .getElementById ('pre'); var
content_Text = newWin.document .createTextNode (previewText);
insertPoint_Tex t.appendChild(c ontent_Text);
var insertPoint_Tit le = newWin.document .getElementById ('title'); var
content_Title = newWin.document .createTextNode (previewTitle);
insertPoint_Tit le.appendChild( content_Title);
var insertPoint_Ico n = newWin.document .getElementById ('icon');
insertPoint_Ico n.src = previewIcon;
}
It absolutely will not work unless I add these two lines:
Code:
newWin2=window. open();
newWin2.close() ;
It's really weird and I don't know how to fix the problem without opening
another window other than the one that I'm generating the preview in. I'm
not a programmer and I'm not that great with javascript, so if a
javascript guru could point me in the right direction I would really
appreciate it.
Comment