0

I am trying to open an Internet Explorer window from Java code as below:

Runtime.getRuntime().exec(folder + ":\\Program Files\\Internet Explorer\\IEXPLORE.EXE  http://google.com/");

That works fine but my requirement is to open the window at a small size, for which I followed the link How do you resize an IE browser window to 1024 x 768. But I don't know how I can use the JavaScript solution from Java code.

I tried passing it on the command line:

Runtime.getRuntime().exec(folder + ":\\Program Files\\Internet Explorer\\IEXPLORE.EXE javascript:resizeTo(1024,768); http://google.com/"); 

But it is not working. Please suggest if you have any idea.

Thanks in advance.

Community
  • 1
  • 1
Ajeet Varma
  • 726
  • 4
  • 20

2 Answers2

0

if you try \\Program Files\\Internet Explorer\\iexplore javascript:resizeTo(1024,768); http://google.com/ on a command line, you will find it does not do what you are expecting.

iexplore does not seem to respect the javascript protocol properly in this scenario.

When i tried, it seems to open the save file dialog rather than running the code. I suggest this is the problem you need to workaround.

I have not investigated further, but you might try a custom protocol handler or some other way of having iexplore run the js, whether from the CLI or otherwise.

CharlieS
  • 1,432
  • 1
  • 9
  • 10
-2
javascript:resizeTo(1024,768); vbscript:resizeto(1024,768) 

Will work in IE7, But consider using something like

javascript:moveTo(0,0);resizeTo(1024,768);

because IE7 doesn't allow the window to "resize" beyond the screen borders. If you work on a 1024,768 desktop, this is what happens...

Firefox: 1024x768 Window, going behind the taskbar. If you drop the moveTo part, the top left corner of the window won't change position.(You still get a 1024x768 window) IE7: As close as possible to the requested size without obscuring the taskbar or allowing any part of the window to lie beyond the screen borders. safari: As close as possible to the requested size without obscuring the taskbar or allowing any part of the window to lie beyond the screen borders, but you can ommit the moveTo part. Safari will move the top left corner of the window for you. Opera: Nothing happens. Chrome: Nothing happens.

This quote is from: Tolle you can find his post here: How do you resize an IE browser window to 1024 x 768

Hopefully this is help full to you!

Community
  • 1
  • 1
berm
  • 27
  • 9
  • As in my question i have already mentioned that i have followed the same link to which you have preferred , but my problem is that how i integrate this `javascript:resizeTo(1024,768);` in my java code . – Ajeet Varma Nov 13 '14 at 08:17
  • @AjeetVarma Well, So stupid from me! I apologize, will not happen again. Good luck with your search to the answer! – berm Nov 14 '14 at 09:13