aspose file tools*
The moose likes Java in General and the fly likes Can we disable javascript in IE programatically? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Java in General
Bookmark "Can we disable javascript in IE programatically?" Watch "Can we disable javascript in IE programatically?" New topic
Author

Can we disable javascript in IE programatically?

Shyam kumar
Ranch Hand

Joined: May 21, 2006
Posts: 146
Hi,

I need to write a java code to disable javascript dynamically in IE6. I'm very curious to know if we can do that? I would appreciate any kind of help.

Thanks,
SK
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42264
    
  64
What kind of Java code is this - a desktop application? A signed applet? Part of of a web app? If it's part of a web app, then this is not possible (imagine the security implications of a web app that can alter browser settings!). If it's not part of a web app, then you should tell us in more detail what the actual problem is, and why you think Java would be a good choice for solving it.


Ping & DNS - my free Android networking tools app
Srikanth Nutigattu
Ranch Hand

Joined: Oct 30, 2007
Posts: 114
Don't know if it's what you mean:

1. You are creating a web app (Servlets/JSP) and want to disable/ignore some Java script functionality in THIS Web app.
Then you can conditionally include the JS in the web page by checking the USER-AGENT Header from the client request.

If you are referring to something else.. elaborate.

Thanks.
Deepak Bala
Bartender

Joined: Feb 24, 2006
Posts: 6661
    
    5

I need to write a java code to disable javascript dynamically in IE6


What functionality needs javascript to be disabled


SCJP 6 articles - SCJP 5/6 mock exams - More SCJP Mocks
Shyam kumar
Ranch Hand

Joined: May 21, 2006
Posts: 146
Ok Guys, thanks for taking interest in this. Let me explain why I need the javascript to be disabled.
We have a web app which is functionally tested by ruby scripts. These ruby script test functionality of the site only when javascript is enabled. Now we need to write ruby scripts which test the functionality of the site when javascript is disabled. Our tested did some initial research and did not find any way to disable the javascript through ruby.
I'm thinking of writing a simple standalone java program which disables and enable the javascript dynamically. This java program can then be executed by ruby script before performing the funtional test.
I just hope I have made myself clear here.
Thanks,
SK
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42264
    
  64
What is the connection between Ruby testing code and an instance of IE? Does Ruby start an embedded IE instance?
Shyam kumar
Ranch Hand

Joined: May 21, 2006
Posts: 146
Hi Dittmer,

Ruby scripts open the IE browser and then start performing the functional test's on in like clicking the clicking on the register link, enter a test user details, then submitting the registration request. Checking if the user is logged in or not after successful registration. These scripts emulate the user behavior and do functional testing the complete website.
These ruby scripts launches the IE browser and then replicate the end user behavior and checks whether the functionality is working as expected. By default the browser javascript is enabled so these scripts replicate the end user behavior when javascript is enabled. Now our tester need to write some new ruby scripts which emulates the user behavior when javascript is disabled.
To work on that I want to write a small java code which runs initially and disable the javascript first and then he can ruby scripts.

Thanks,
SK
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42264
    
  64
If it's possible to control an IE instance that completely through Ruby code, maybe there's a way to disable JS from within Ruby. Seems easier than to involve Java.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18648
    
    8

We do have a Ruby forum here at the Ranch, if this turns out to be a Ruby question. Just ask and any moderator will move the post over there.
Shyam kumar
Ranch Hand

Joined: May 21, 2006
Posts: 146
Thanks Paul/Ulf for the suggestion, I'll post this query there too to see if this thing is possible through Ruby or not. But from java point of view, is this thing possible in Java?
Thanks,
SK
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

Shyam kumar wrote: I'll post this query there too ...

Please do not. It will be removed.

Please read this for more information.

If you want this topic moved there, please just ask.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Shyam kumar
Ranch Hand

Joined: May 21, 2006
Posts: 146
No Thanks, I want to keep it here. If I don't get any solution from this forum, I'll request for the post to be moved.
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18648
    
    8

Yes, well don't hold your breath waiting for solutions in which Java is used to hack the browser settings. If it is possible then it's a security violation. You aren't going to get advice on how to breach browser security from this forum.
Shyam kumar
Ranch Hand

Joined: May 21, 2006
Posts: 146
Hi Paul, I'm sorry if by asking my question it is felt that I'm trying to take advice on how to breach security of browser
In my previous post I explained exactly why we need to do this. And all I'm looking for is an answer from this community whether it is possible through java or not.
If not then, I'm curious to know the reason and if yes then at least I know I'm thinking in the right direction.
Thanks,
SK
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

Whose browser are you trying to hack?
Shyam kumar
Ranch Hand

Joined: May 21, 2006
Posts: 146
Nobody's... Please read my query.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61413
    
  67

My point is, if it's a browser on one of you own systems, just set it by hand and be done with it.

If it's not, then it's hacking someone else's browser, and such discussion is disallowed.

Perhaps you need to elaborate on your relationship with the browser that you are trying to manipulate.
Ulf Dittmer
Marshal

Joined: Mar 22, 2005
Posts: 42264
    
  64
Shyam's second post goes into some detail of what's going on, and it's a legitimate problem. I'd look into whether the Ruby library/feature used to drive the browser supports this.
Shyam kumar
Ranch Hand

Joined: May 21, 2006
Posts: 146
Shyam kumar wrote:Ok Guys, thanks for taking interest in this. Let me explain why I need the javascript to be disabled.
We have a web app which is functionally tested by ruby scripts. These ruby script test functionality of the site only when javascript is enabled. Now we need to write ruby scripts which test the functionality of the site when javascript is disabled. Our tested did some initial research and did not find any way to disable the javascript through ruby.
I'm thinking of writing a simple standalone java program which disables and enable the javascript dynamically. This java program can then be executed by ruby script before performing the funtional test.
I just hope I have made myself clear here.
Thanks,
SK


Hi Bibeault,

We are working in XP agile methodology in which continuous integration and testing is an integral part of development process. You may know this but let me explain in a little detail.
Our business analyst gather business requirements and break them into small stories.
Those stories comes in the form of a story card to us for development.
When me and my pair completes the stories, we hand over the story card to the Tester.

The role of our tester is a little different here. The tester do not perform the unit test because we test drive our code so unit test are a part of Junit test suit.
In our team the tester writes ruby scripts that emulate the end user behaviour and test the business functionality. These new scripts are added to the existing ruby test suite and then after each successful build, the entire suite of ruby scripts run which ensures that the new functionality has not broken any existing functionality. These ruby scripts run unattended and performs tasks such as opening the IE browser, passing the site url and then performing operations such as registration or login; adding some user-credentials and checking if successful login is done or not.
Now wherever these scripts run, they run unattended; we cannot manually disable or enable javascript and then let the ruby scripts run.
By default javascript of our browser remains enabled so these scripts test functionality in which javascript is enabled.
But now we need to test our site's functionality when javascript is disabled. In such a scenario we need a way to disable javascript dynamically so that the new variations to our ruby scripts can be added. If we have a java code that disables this javascript of browser dynamically then we will be able to run our ruby scripts for testing our site's functionality when javascript is disabled.

Does that give you a better idea of the overall discussion?

Thanks,
SK
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18648
    
    8

Yes, that's pretty much what you have said already. That may be all above-board and so on but I don't see that it addresses anything about Java at all. I still don't think that anybody is going to post here with a magic thing which allows Java to hack into the browser and mess with its configuration.

I agree with what Ulf said some time ago -- if Ruby can manipulate the browser in the way you described, there's a good chance it can manipulate the browser configuration too. So I too don't understand your insistence on looking for a Java solution when the Ruby solution is more likely to exist.
Shyam kumar
Ranch Hand

Joined: May 21, 2006
Posts: 146
Hi Paul, From the feedback that I got from our tester is that it is not possible to disable javascript dynamically through Ruby!!! So that is the reason why I was thinking whether there can be a possible solution for this using java
Andrew Monkhouse
author and jackaroo
Marshal Commander

Joined: Mar 28, 2003
Posts: 11476
    
  94

I'm wondering if this is a case where the OP has a hammer so they are trying to solve the problem as though it is a nail?

If the problem is one where certain functionality needs to be tested in web browser(s) with different functionality enabled / disabled, I think this is more a regression test issue, and is more likely to be solved using something like Selenium. I understand that Selenium can turn on/off JavaScript within Mozilla based browsers, so there may be the same functionality with IE.


The Sun Certified Java Developer Exam with J2SE 5: paper version from Amazon, PDF from Apress, Online reference: Books 24x7 Personal blog
Srikanth Nutigattu
Ranch Hand

Joined: Oct 30, 2007
Posts: 114
What you can do is,
Try to create two profiles for firefox, one with JS enabled and another with JS disabled.
Now ask the Selenium (or your ruby testing scripts if possible) to load these profiles before testing.

By, this you can test the functionality with both JS Enabled and disabled.

For IE I think it is a tedious task:
I think you need to venture into the MS world,
" you can use the WMI scripting interface which will give you full access to the Windows registry where IE stores this setting. If you haven't got a clue about WMI, WMI Providers and the layout of IE's registry keys"

But, I think you will be better off using Firefox solution than IE.
HTH
Shyam kumar
Ranch Hand

Joined: May 21, 2006
Posts: 146
Thanks Srikant, looks like this is the way to go.
If I get an alternate solution of this problem, I'll share with all you guys. Thanks everyone for enlightening me.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Can we disable javascript in IE programatically?