J
Jarrod Hyder
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_preview() {
var newWin =
window.open('/weblog/pop_up.html','Preview','width=650,height=400');
var previewText = document.forms[0].logtext.value; var previewTitle =
document.forms[0].title.value; var previewIcon = document.preview.src;
var insertPoint_Text = newWin.document.getElementById('pre'); var
content_Text = newWin.document.createTextNode(previewText);
insertPoint_Text.appendChild(content_Text);
var insertPoint_Title = newWin.document.getElementById('title'); var
content_Title = newWin.document.createTextNode(previewTitle);
insertPoint_Title.appendChild(content_Title);
var insertPoint_Icon = newWin.document.getElementById('icon');
insertPoint_Icon.src = previewIcon;
}
And here is the code that works flawlessly to generate the preview:
Code:
function generate_preview() {
var newWin =
window.open('/weblog/pop_up.html','Preview','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.preview.src;
var insertPoint_Text = newWin.document.getElementById('pre'); var
content_Text = newWin.document.createTextNode(previewText);
insertPoint_Text.appendChild(content_Text);
var insertPoint_Title = newWin.document.getElementById('title'); var
content_Title = newWin.document.createTextNode(previewTitle);
insertPoint_Title.appendChild(content_Title);
var insertPoint_Icon = newWin.document.getElementById('icon');
insertPoint_Icon.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_preview() {
var newWin =
window.open('/weblog/pop_up.html','Preview','width=650,height=400');
var previewText = document.forms[0].logtext.value; var previewTitle =
document.forms[0].title.value; var previewIcon = document.preview.src;
var insertPoint_Text = newWin.document.getElementById('pre'); var
content_Text = newWin.document.createTextNode(previewText);
insertPoint_Text.appendChild(content_Text);
var insertPoint_Title = newWin.document.getElementById('title'); var
content_Title = newWin.document.createTextNode(previewTitle);
insertPoint_Title.appendChild(content_Title);
var insertPoint_Icon = newWin.document.getElementById('icon');
insertPoint_Icon.src = previewIcon;
}
And here is the code that works flawlessly to generate the preview:
Code:
function generate_preview() {
var newWin =
window.open('/weblog/pop_up.html','Preview','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.preview.src;
var insertPoint_Text = newWin.document.getElementById('pre'); var
content_Text = newWin.document.createTextNode(previewText);
insertPoint_Text.appendChild(content_Text);
var insertPoint_Title = newWin.document.getElementById('title'); var
content_Title = newWin.document.createTextNode(previewTitle);
insertPoint_Title.appendChild(content_Title);
var insertPoint_Icon = newWin.document.getElementById('icon');
insertPoint_Icon.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.