julia k Posted January 5, 2009 Share Posted January 5, 2009 I'm working on a simple texteditor (yes, I know, there are many already) and the reason I don't want to use one already implemented is because they are too large for what I need, so, I created two buttons: [*]one that will open a popup window (called preview) and write the content of the textarea in the popup window [*]and another one (update preview) which should update the preview popup when clicked My problem is that I cannot clear the content of the preview popup. I tried using the document.clear() function but it's not working as expected, that is the content is cleared alright but after that nothing works... Do you guys have any clue about how can I clear the popup window's content so I can write the new updated content into it? this is a part of my code [just to give you an idea] : // create the preview window when the button is clicked preview_win = window.open('', 'preview', 'width=700,height=400,scrollbars=1,resizable=1'); preview_win.document.write(self.editor.value); preview_win.focus(); // update the popup window's content when the content in the editor has been changed and the preview button has been clicked: if (preview_win && !preview_win.closed) { preview_win.document.clear(); // Clear content. The code below doesn't gets executed... preview_win.document.write(self.editor.value); preview_win.focus(); } Quote Link to comment https://forums.phpfreaks.com/topic/139601-solved-clear-popup-windows-content/ Share on other sites More sharing options...
KevinM1 Posted January 6, 2009 Share Posted January 6, 2009 I'm working on a simple texteditor (yes, I know, there are many already) and the reason I don't want to use one already implemented is because they are too large for what I need, so, I created two buttons: [*]one that will open a popup window (called preview) and write the content of the textarea in the popup window [*]and another one (update preview) which should update the preview popup when clicked My problem is that I cannot clear the content of the preview popup. I tried using the document.clear() function but it's not working as expected, that is the content is cleared alright but after that nothing works... Do you guys have any clue about how can I clear the popup window's content so I can write the new updated content into it? this is a part of my code [just to give you an idea] : // create the preview window when the button is clicked preview_win = window.open('', 'preview', 'width=700,height=400,scrollbars=1,resizable=1'); preview_win.document.write(self.editor.value); preview_win.focus(); // update the popup window's content when the content in the editor has been changed and the preview button has been clicked: if (preview_win && !preview_win.closed) { preview_win.document.clear(); // Clear content. The code below doesn't gets executed... preview_win.document.write(self.editor.value); preview_win.focus(); } From what I've been able to dig up, the clear() method is deprecated and should not be used. Instead, you have a couple of options: You can create a new document by using document.open(). You can make the document contain only an empty string by using document.write(''); If your popup has a main content element, you can set its innerHTML to an empty string as well. From what I understand, document.write() always adds text to the beginning of the document, rather than append to the end of the document. If this is the case, then option 2 is probably your best bet. Quote Link to comment https://forums.phpfreaks.com/topic/139601-solved-clear-popup-windows-content/#findComment-730788 Share on other sites More sharing options...
julia k Posted January 6, 2009 Author Share Posted January 6, 2009 Hi! I tried different scenarios but none of them worked so far... It seems that the document.write method always appends the text... maybe I'm missing something here, I don't know... I'll keep trying. Quote Link to comment https://forums.phpfreaks.com/topic/139601-solved-clear-popup-windows-content/#findComment-730794 Share on other sites More sharing options...
KevinM1 Posted January 6, 2009 Share Posted January 6, 2009 Hi! I tried different scenarios but none of them worked so far... It seems that the document.write method always appends the text... maybe I'm missing something here, I don't know... I'll keep trying. Hi! I tried different scenarios but none of them worked so far... It seems that the document.write method always appends the text... maybe I'm missing something here, I don't know... I'll keep trying. Do you have a specific element that you're writing to in the popup window? Quote Link to comment https://forums.phpfreaks.com/topic/139601-solved-clear-popup-windows-content/#findComment-730931 Share on other sites More sharing options...
julia k Posted January 7, 2009 Author Share Posted January 7, 2009 no, I don't but I've found my answer. You see, the first time I opened the popup window I was writing into it the whole content from the textarea and nothing else and after that, when I was trying to update the content, the new content was appended to the one existent one in the popup. So, I thought about what you said about innerHTML = '' and I changed the way I was initially writing the content in the popup, by that I mean that I inserted the basic html tags like a doctype head and body and inside the body I was then writing the content from the textarea. And that helped because when I'm now updating the popup all I have to do is get a reference to the popup's body tag and set to an empty string: preview_win.document.getElementsByTagName('body')[0].innerHTML = ''; and then writing the new content. thanks, Nightslyr Quote Link to comment https://forums.phpfreaks.com/topic/139601-solved-clear-popup-windows-content/#findComment-731228 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.