Hi

Have been battling for hours with a simple function asking a window that was opened with window.open() to be closed. Works fine in Firefox but IE just keeps creating an error "Permission Denied".

I doubted my code as a consequence, but have used sample code to check this and though the sample works over the net on the providers site, locally I still get "Permision Denied". Any ideas would be great.

Sal:rolleyes:

Dani AI

Generated

As showed, the code works in Firefox but IE throws "Permission denied" when trying to close a PDF pop-up — and the detail that the same sample works from the provider's site but fails locally is a crucial clue. In IE this usually points to security-zone / plugin behavior rather than a JavaScript bug: pages opened from the local file system (file://) get more restrictive rights (Local Machine Zone), and PDF viewers/plug‑ins can take over the window so the original script loses safe access. IE then raises "Permission denied" when script tries to touch that window object.

Practical ways to diagnose and fix:

  • Reproduce the page over HTTP (run a tiny local web server). If it works via http://, the local-file security zone was the culprit. Changing users' IE security settings is not recommended.
  • Avoid opening the PDF as the first navigation target of the new window. Open a script-owned window (about:blank or a small HTML wrapper) and then set its location or embed the PDF inside an HTML page; that keeps a controllable window object across browsers.
  • Protect calls to the old popup with a guard and try/catch so IE does not throw an unhandled exception. For example, check the popup exists and is not closed and wrap close() in try/catch; then open (or reuse) a named blank window and assign its location to the PDF.

Also make sure the trigger anchor has an explicit href and prevents default navigation (rather than relying solely on onclick), and test with a plain HTML page instead of a PDF to confirm whether the plugin is involved. These steps typically resolve the Permission Denied errors seen in IE6/IE7 when dealing with PDF pop-ups.

(Thanks to for asking for the full code earlier — that prompted the local-vs-http test which usually nails this.)

Recommended Answers

All 2 Replies

Member Avatar for Member #114696

well give the whole code and we'll help u out..

well give the whole code and we'll help u out..

The following is the line of code that prompts the window to open on the click of some text (In this case, either "User's Terms and Conditions" or "Privacy Policy"

<div class="rodsCentred"><div class="rodBackground"><a id="T&C" onclick="F_OpenPDFWindow('../pdfs/legal/UsersTermsAndConditions_V1_Jan2004.pdf')">User's Terms and Conditions</a></div><div class="rodBackground"><a id="PPolicy" onclick="F_OpenPDFWindow('../pdfs/legal/PrivacyPolicy_V1_Jan2004.pdf')">Privacy Policy</a></div>

As I was having trouble in IE with window.focus(), I decided to close the window (opened with window.open()) before re-opening if the alternative text was clicked. That is is someone first looked at the Terms and Conditions and then decided to look at the Privacy Policy, if that makes sense. Thus the function is as follows:


function F_OpenPDFWindow(NewWin)
{
if(PDF_PopUp!=undefined)
{
PDF_PopUp.close();
}
var PageContent=NewWin;
PDF_PopUp = window.open(PageContent, "pdfWindow","width=750,left=30,top=40,scrollbars");
}


This code works fine in Firefox, but as mentioned before, IE just throws and error stating "Permission denied". Have almost decided that I am going to have to completely re-think how I present this data!! Very frustrating so ... thanks for your help!

Sal;)

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.