I need to know if you can add a javascript within

my_window.document.write( );

as

my_window.document.write( '<html><head><script type="text/javascript" src="http://somesite.com/xxy.js"></script></head></html>' );

When i add the code as shown above, it gets printed inthe parent window, how do i overcome this, if there's no way to overcome this, please suggest a new technique.

note: i am forced to use a child window in this case. (so its a must)

Localp,

It would help to see the code that opens the child window. Could you post it please.

Airshow

Here you go >>

<html>
	<head>
		<title>test </title>
	</head>

	<script type="text/javascript">
	   
		var my_window;
	   
		function popuponclick()
		{
			my_window = window.open("",	"mywindow","status=1,width=350,height=150"); 
	 
			if (my_window.opener == null) 
	 
			my_window.document.write 
			(
			'<html><head>'+
			'<title>Hello</title>'+
			'<SCRIPT></SCRIPT>'
			'</head>'+
			'<body>'+
			
			
			 '</body></html>'
			);
		}
	 
		function updateAndClose()
		{
			document.getElementById("my_text").value = my_window.document.getElementById("my_window_text").value; 
			my_window.close(); 
		}
				
		function setFocus()
		{
			document.getElementById("my_window_text").focus();
		}		
		
	</script>
	
	<body>
		  <a href="javascript: popuponclick()">Open Popup Window</a>
		  
		  <br/>
		  
		  <input type="text" id="my_text" value="" readonly />
		  
	</body>

</html>

The easiest thing to do is to create a separate web page (my_popup_page.html) containing all the HTML you wish to see in the popup window. Then open the window with

my_window = window.open("my_popup_page.html",	"mywindow", "status=1,width=350,height=150");

It gets a bit trickier if the content need to be dynamically generated, in which case there's really two major options:

1. Server-side script - eg. PHP
Change the page extension from .html to .php and write php script in the page to build the HTML dynamically. Pass any necessary paramerters with the my_popup_page.php request (not difficult). The dynamically built page will appear in the popup window.

2. Javascript/DHTML
Serve the page into the popup window with an HTML skeleton and javascript which requests content from the opener window, then dynamically inserts it into the document.

Both approaches may require not-insignificant coding, but only if the page needs to be dynamically built.

Airshow

The easiest thing to do is to create a separate web page (my_popup_page.html) containing all the HTML you wish to see in the popup window. Then open the window with

my_window = window.open("my_popup_page.html",	"mywindow", "status=1,width=350,height=150");

It gets a bit trickier if the content need to be dynamically generated, in which case there's really two major options:

1. Server-side script - eg. PHP
Change the page extension from .html to .php and write php script in the page to build the HTML dynamically. Pass any necessary paramerters with the my_popup_page.php request (not difficult). The dynamically built page will appear in the popup window.

2. Javascript/DHTML
Serve the page into the popup window with an HTML skeleton and javascript which requests content from the opener window, then dynamically inserts it into the document.

Both approaches may require not-insignificant coding, but only if the page needs to be dynamically built.

Airshow

Ok, i am trying the first method that you suggested. Where do you want me to have the php code to open a child window. Is it between code line number 16-26 (look at the code above) ? i tried placing it there, but the child window doesn't pop up.

any idea what went wrong?

Locap,

Delete all your lines 14 to 27.

Try with a simple .html file first. You only need to go to .php if you need to build the page dynamically.

To get you started, the .html file can just say "Hello World!"

<html>
<head>
<title>Hello World</title>
<style>
</style>
<script type="text/javascript">
</script>
</head>

<body>

<h1>Hello World!</h1>
		  
</body>
</html>

Save this as my_popup_page.html in the same folder as your main page.

The javascript statement my_window = window.open("my_popup_page.html", "mywindow", "status=1,width=350,height=150"); should then open a new window displaying your Hello World file.

Airshow

Locap,

Delete all your lines 14 to 27.

Try with a simple .html file first. You only need to go to .php if you need to build the page dynamically.

To get you started, the .html file can just say "Hello World!"

<html>
<head>
<title>Hello World</title>
<style>
</style>
<script type="text/javascript">
</script>
</head>

<body>

<h1>Hello World!</h1>
		  
</body>
</html>

Save this as my_popup_page.html in the same folder as your main page.

The javascript statement my_window = window.open("my_popup_page.html", "mywindow", "status=1,width=350,height=150"); should then open a new window displaying your Hello World file.

Airshow

yeah, the HTML thing seems to work. thanks a lot.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.