[thelist] Javascript: Preview a textarea in another window

VOLKAN ÖZÇELİK volkan.ozcelik at gmail.com
Sat Jan 28 12:36:13 CST 2006


Seems like overcomplicating things,

Why don't you open a server-side page with a real onload handler and
use a reference to the opener instead of overriding the onload event
from the page that opens it.

---the opened window's html (w)---
<script type="text/javascript">
  window.onload=function(){
     processOpener();
  }

  function processOpener(){
     var strValue = opener.document.getElementById("thetextarea").value;
    ...
  }
</script>
<body>...</body>

Or am I oversimplifying things?

If you try to attach the onload event to a "not fully loaded" window,
chances are
i. you will have synchronization problems.
ii. you may see two windows being opened instead of one in slow
connection speeds due to (i), which is really hard to demonstrate in a
development environment but will be a real pain in the rear in prod.
iii. you may need to write stubs to check that the window is really
opend and use set intervals, timeouts to check them:

--- the opened window w's source---
var g_blnLoadedFully=false;
window.onload=function(){
   g_blnLoadedFully=true;
};
funciton loadedFully(){return g_blnLoadedFully;}

---opener's source---

var w=null;/*global reference to window*/
function someEventHandler(evt){
   ... open the window ...
   processOnload();
}

function processOnload(){
  /*if there is a window, the window has a function defined and that
function returns true*/
  if(w && w.loadedFully && w.loadedFully(){
     ...do my logic here.
   }
   else {
     setTimeout("processOnload();",200);/*check later*/
   }
}

...

These are the problems that I can see. The important thing is, there
may be far a lot of problems specific to your logic that I cannot see.


HTH,
--
Volkan Ozcelik
+>Yep! I'm blogging! : http://www.volkanozcelik.com/volkanozcelik/blog/
+> My projects/studies/trials/errors : http://www.sarmal.com/



More information about the thelist mailing list