Code Snippets

  

JavaScript Source Code


Welcome to Dream.In.Code
Getting Help is Easy!

Join 98,764 Programmers for FREE!. Ask your question and get quick answers from Dream.In.Code experts. There are 1,039 online right now! We're the #1 programming help community on the internet! Registration is fast and FREE... Join Now!

Chat LIVE With a Expert

Register to Make This Box Go Away!



Create Pop-Up with Elements

I modified this so its more understandable. ;-) Functions to: 1) Open a pop-up window. (newWindow) 2) Create an element. (newElement) In this example they are used together to create a pop-up window wherein we can modify it through the main window. We can call functions back on the main window (though its not shown here now) like this: Click me! Keep in mind that we could, to go more advanced, add span elements inside the div created in the example to create a more functional document. Have fun. :)

Submitted By: okyup
Actions:
Rating:
Views: 1,851

Language: JavaScript

Last Modified: November 11, 2006
Instructions: Copy Paste.

Snippet


  1. <html>
  2. <head>
  3. <script type="text/javascript">
  4.  
  5. var pop0=null;
  6.  
  7. function customSetup(URL,name,param,title)
  8. {
  9.  winbody=newWindow(URL,name,param,title);
  10.  newElement('div',winbody,"this is my inner HTML!");
  11. }
  12.  
  13. function newWindow(URL,name,param,title)
  14. {
  15.  if (URL==null) URL='';
  16.  win=window.open(URL,name,param);
  17.  windoc=win.document;
  18.  windoc.write("<html><head><title>"+title+"</title></head>");
  19.  windoc.write("<body></body></html>");
  20.  windoc.close();
  21.  winbody=windoc.getElementsByTagName('body')[0];
  22.  if (pop0==null) pop0=windoc;
  23.  return winbody;
  24. }
  25.  
  26. function newElement(tag,node,iHTML)
  27. {
  28.  element=pop0.createElement(tag);
  29.  if (iHTML!=null)
  30.   element.innerHTML=iHTML;
  31.  node.appendChild(element);
  32. }
  33.  
  34. </script>
  35. </head>
  36.  
  37. <body onLoad="customSetup(null,'newWin','width=250,height=250','My Title!');">
  38.  
  39. </body>
  40. </html>

Copy & Paste


Comments


There are currently no comments for this snippet. Be the first to comment!

Add comment


You must be registered and logged on to </dream.in.code> to leave comments.





Live Help!

Tutorials

Programming

Web Development

Reference Sheets

Code Snippets

Bye Bye Ads

Free DIC T-Shirt

T-Shirt Example

Related Sites

Monthly Drawing

Thumb Drive

Partners

Top Contributors

Top 10 Kudos This Month
-->