We help IT Professionals succeed at work.

We've partnered with Certified Experts, Carl Webster and Richard Faulkner, to bring you two Citrix podcasts. Learn about 2020 trends and get answers to your biggest Citrix questions!Listen Now

x

ActiveX Errors in JavaScript

adnan_rais
adnan_rais asked
on
Medium Priority
643 Views
Last Modified: 2008-02-01
I've made a link in JavaScript which open MS Excel & loads the requested file in it. On clicking the link, an option appears asking "An ActiveX control on this page might be unsafe to interact with other parts of the page. Do you want to allow this interaction?"

If I click YES, the MS Excel opens & the file is loaded successfully. But If I click NO, the page returns with an "ERROR LOADING THE PAGE". It should not return this error. The code is as

<head>
<script language="JavaScript">
     function startXL(str)
     {
          var app = new ActiveXObject("Excel.Application");
          if(app!=null){
               app.visible = true;
               if(str=="0"){
                    app.workbooks.open("file:///c:/MIS/Reports/Qatar/ABA/2005/2005-ABA-ANALYSIS.xls");
               }else
               if(str=="1"){
                    app.workbooks.open("file:///c:/MIS/Reports/Qatar/ABA/2006/2006-ABA-ANALYSIS.xls");
               }
          }
          return false;
     }
</script>
</head>

<body>
<a href="#" onClick="startXL(0);return false;" style="font-family:arial;color:darkgreen;font-size:12px;text-decoration:none;">ABA Report 2005</a>
<br><a href="#" onClick="startXL(1);return false;" style="font-family:arial;color:darkgreen;font-size:12px;text-decoration:none;">ABA Report 2006</a>
</body>
Comment
Watch Question

Try below:
<script language="JavaScript">
window.onerror=new Function ('return true;');
</script>

Author

Commented:
ok fine on clicking NO, the page doesn't return any error but the URL becomes like this "file:///C:/MIS/QatarMIS.html#" & when I click on some other link, no response occurs. WHY?

Author

Commented:
I think there's some problem with the "#" sign placed in the URL

Author

Commented:
I've to refresh the page every time to continue functioning

Author

Commented:
any idea bubbledragon?
ActiveX alert ask for once, if click no, all will not run until you refresh the page.

Author

Commented:
Tell me another appropriate solution b'coz ofcourse the Web Users r not going 2 refresh the page after first ActiveX alert, if I do use ur code

Author

Commented:
Tell me another appropriate solution b'coz ofcourse the Web Users r not going 2 refresh the page after first ActiveX alert, if I do use ur code
Commented:
Unfortunately, if the user clicked NO, the browser will not enable your activeX to start until the user refreshes the page (and then will be asked again for enabling activeX execution).

The better way then would be to prevent prompting when an activeX is used on your page.
But this can be a security issue though, and that means that you can change the browser's configuration of all your users.

Is your page opened (by your users) through a web server (local or internet) or simply on a local file system ?

If opened on a web server and if you can change the browsers config, simply add the domain of your server in the Trusted Sites list, this should work then better (if not, just check the security level for trusted site and select the right otion for your activex)

If opened locally, through a file system, there is a trick you can use on IE.
In your source code, add a line before the <HTML> tag like this :

<!-- saved from url=(0025)http://www.domainname.com -->

By doing this, IE will act (for security purposes) just like your web page is on the domain written in this line (in this case, www.domainname.com). All you have to do then is to add this domain on the trusted sites, and it should work.
Simply put a domain your are sure doesn't exist (still for security reasons).
The numbers in the code are just the length of the url (including http://).

Hope this will help.

Not the solution you were looking for? Getting a personalized solution is easy.

Ask the Experts

Author

Commented:
Thanx smaccari, u r really a very smart EXPERT ;-)
Access more of Experts Exchange with a free account
Thanks for using Experts Exchange.

Create a free account to continue.

Limited access with a free account allows you to:

  • View three pieces of content (articles, solutions, posts, and videos)
  • Ask the experts questions (counted toward content limit)
  • Customize your dashboard and profile

*This site is protected by reCAPTCHA and the Google Privacy Policy and Terms of Service apply.

OR

Please enter a first name

Please enter a last name

8+ characters (letters, numbers, and a symbol)

By clicking, you agree to the Terms of Use and Privacy Policy.