开发者

Access Javascript from Java

开发者 https://www.devze.com 2023-03-11 09:33 出处:网络
I m trying to access JavaScript function from Servlet code. But I\'m getting the error shown below. Here is the code:

I m trying to access JavaScript function from Servlet code. But I'm getting the error shown below. Here is the code:

out.println("<FRAME src=\"javascript:parent.newWindow('" + URL+ "') \" scrolling=No noresize />");

And this is开发者_如何转开发 the error that occurs in JavaScript:

Object does not support this property or method;


You can't access a Javascript function from your servlet code. Javascript executes on the client (= your user's browser) and the servlet code executes on your server (for example Tomcat, JBoss, whatever you're using).

What are you trying to accomplish with your code? I'm sure there's a simpler way to do it than what you just described.

[edited]

I see you just updated your description, so here's my view:

I'm guessing that you want to display a page to the user and when the page is displayed, you want to open a new window which will display another page using the URL parameter to point its address. If this is the case, you should probably just do this in the first page's onLoad() Javascript event using window.open().


There is no newWindow property on a window object (which is what parent references), so this is not unexpected.

Maybe you are looking for the open method instead?

If so, then:

  • Putting it as the src of an iframe is a very strange thing to do
  • It will probably be zapped by pop-up blockers


Ok. You try to generate javascript code inside Servlet code. When you do, your code goes to Web browser and it's seen there as a html document with javascript inside. So, your error rather comes from web browser and links to javascript error. Probably it's newWindow method. To open new window you should call window.open() function, I guess.

0

精彩评论

暂无评论...
验证码 换一张
取 消