how to include javascript in new window using window.open code

The same way you include scripts in any other page. The window.open() method requires a URL as an argument. That URL will, of course, reference a page. That page will have whatever content the page author places in it, including scripts.

If you are asking about techniques for accessing parent-child DOM elements, you need to be more specific in your question.

hi
I used this code to open new window newwindow2=window.open(' ','popup','scrollbars=1,height=800,width=800'); In that window itself i need script.
Is this scripting is correct or not document.write('<'+'script type="text/javascript"' + 'src="jsr_class.js"><'+ '/script>'); Please reply soon

It depends on the DOCTYPE you're using. The "document.write()" method is deprecated in XHTML.

You'd also need a space before "src".

hi
how to call a function inside script in document.write.
For example.
document.write('<'+'script type="text/javascript"' + 'src="jsr.js"><'+ '/script>');

In this jsr.js file i need to call one function how can i call using document.write method

I don't know how to be more clear. Have you read and understood the answers you've already been given?

1. The document.write() method is out-of-date. However, if you're using an older DOCTYPE, it should still work for you.

2. That being the case, you can author an entire page using document.write() , so you can place HTML, scripts, event handlers, whatever you like, on that page, just as you would any other page.

3. The code you show uses a plus sign to concatenate strings, for some reason. It isn't necessary, but as you've shown it, there would be no space between "javascript" and "src=". You need to add a space before "src".

4. The document.write() method doesn't "call" anything. It writes a page. That page will need to have the code necessary to call a function... which is the same for any page.

5. If you plan on using document.write() , you'll need a corresponding document.close() .

My questions to you would be:

1. Why are you using document.write() ? If you know enough to write the code into your new window, chances are you know enough to simply author that page offline, and refer to it by URL in your window.open() call.

2. Could you include the javascript in your main page, and have it act on your child window through DOM methods?

Also, please refrain from coloring or formatting your posts. We like to reserve formatting for code only.

I don't know how to be more clear. Have you read and understood the answers you've already been given?

1. The document.write() method is out-of-date. However, if you're using an older DOCTYPE, it should still work for you.

2. That being the case, you can author an entire page using document.write() , so you can place HTML, scripts, event handlers, whatever you like, on that page, just as you would any other page.

3. The code you show uses a plus sign to concatenate strings, for some reason. It isn't necessary, but as you've shown it, there would be no space between "javascript" and "src=". You need to add a space before "src".

4. The document.write() method doesn't "call" anything. It writes a page. That page will need to have the code necessary to call a function... which is the same for any page.

5. If you plan on using document.write() , you'll need a corresponding document.close() .

My questions to you would be:

1. Why are you using document.write() ? If you know enough to write the code into your new window, chances are you know enough to simply author that page offline, and refer to it by URL in your window.open() call.

2. Could you include the javascript in your main page, and have it act on your child window through DOM methods?

Also, please refrain from coloring or formatting your posts. We like to reserve formatting for code only.

Thanks a lot for your response.I got the result.

This article has been dead for over six months. Start a new discussion instead.