How to get around “Access is Denied” in a Window.Open() JavaScript call

July 20, 2006

I’ve made two changes to the Forms and Field lister I posted yesterday – the original post has been altered to include them.

First and foremost, the line to paste into Start->Run to install the program into the registry was being altered by WordPress. Though the text looked identical, the double quotes were being changed to a different character. The result was you would receive an “invalid key name” error. If, in DOS, you went back and replaced the double quote imposters with actual double quotes, it would run fine. So I have wrapped that line with PRE and TT tags in the original post and provided a batch file in case anyone still has problems.

Second, it was discovered that some Windows computers would block the popup. There would be no error given or any indication of what happened beyond a dialog box flashing up on the screen and disappearing. I debugged this by adding alert(1),alert(2)…alert(n) messages after every line of the source code. Once I did that, IE was kind enough to tell me that it was bombing out due to an “Access is Denied” error triggered from my Window.Open(“”,”tcc_formlist”,”"); command. That line worked at my office, but bombed out on one of my home computer.

The reason is that Windows now blocks one window or frame accessing another window or frame that is in a different domain (or security zone I believe). This technique is calls Cross Frame Scripting. The problem is that what I am doing with these tools IS exactly working across two frames/windows. Luckily there is a way around this.

The JavaScript Mini-FAQ, available here: http://www.dannyg.com/ref/jsminifaq.html#q15, has a good description of this issue and the work around:

Q. What does the IE “Access is Denied” error mean?
A. The “Access Denied” error in any browser usually means that a script in one window or frame is trying to access another window or frame whose document’s domain is different from the document containing the script. What can seem odd about this is that you get this error in IE for Windows frequently when a script in one window generates a new window (with window.open()), and content for that other window is dynamically created from the same script doing the opening. The focus() method also triggers the error.
The error can also occur if scripts try to access objects, properties, or methods that have been locked down by Microsoft’s security platoon. For instance, the document.styleSheets.rules property used to be accessible in IE 5 and IE 5.5, but is not in IE 6.

For the new window problem, there is a bit of history associated with the problem and workarounds. For example, the problem occurs frequently when the scripts are being run from the local hard disk. You get a clue about the situation in the titlebar of the new window: It forces an about:blank URL to the new window, which is a protocol:domain that differs from wherever your main window’s script comes from. If, however, you put the same main window document on a server, and access it via http:, the problem goes away.

There is a workaround for the local-only problem: In the first parameter of the window.open() method call, load a real document (even if it is a content-free HTML document) into the sub-window before using document.write() to generate content for the subwindow. The loading action ‘legitimizes’ the window as coming from the same domain as your main window’s document.

(This solution does not affect scripts that load a page from a secure server into a separate window or frame. An http: protocol in one window and https: in the other–even if from the same server.domain–yield a security mismatch and “Access Denied.” Setting the document.domain properties of both pages may solve the problem (but I am unable to test it for sure).)
[...]

I’ve updated the original code to include this fix.
Window.Open(“”,”tcc_formlist”,”");
is now
Window.Open(“file:///c:/Windows/web/formlist.htm”,”tcc_formlist”,”");

The end result is that window.open command quickly opens the script before the dynamic content is displayed. This little blip is not noticeable on my daughters computer. I don’t think it will be a major slowdown. Due to how the code is written, the whole of the JS routine is not executed. The biggest negative is that the script now has a reference to what I expect the file name to be on your computer. If you rename the script, you need to change that reference in the source. I doubt many people will rename the script.

That was kind-of a ramble… Does that all make sense?

Share and Enjoy:
  • del.icio.us
  • Fark
  • Reddit
  • Digg
  • DZone
  • email
  • Facebook
  • FriendFeed
  • Google Bookmarks
  • Netvibes
  • Ping.fm
  • Posterous
  • Slashdot
  • StumbleUpon
  • Suggest to Techmeme via Twitter
  • Technorati
  • Tumblr
  • Yahoo! Bookmarks
  • Add to favorites
  • Blogosphere News
  • HackerNews
  • Identi.ca
  • LinkedIn
  • MySpace
  • Print
  • Yahoo! Buzz

Comments

4 Responses to “How to get around “Access is Denied” in a Window.Open() JavaScript call”

  1. Vaishali on August 22nd, 2006 2:18 am

    Hi Brian,

    I am doing exactly the same thing while trying to open a file from my local hdd.

    I have

    In my body, and corresponding javascript function is:

    function OpenSpecifiedFile() {
    var filename = “file:///c:/procedure.txt” ;
    window.open(filename,”abcd”,”"); //I added third “” after I saw this blog
    }

    I have currently hardcoded the filename although I can very well pick it up from the filectrl.

    My page is hosted on default .net webserver packaged with VS2005.

    :(

    Do I need to change the security zone in my IE 6?

    Vaishali

  2. deep on March 5th, 2007 5:46 am

    HI vaishali,
    My requirement is same as vaishali. I tried the solution as told by Brian.But it din’t help.

  3. alyssa on December 3rd, 2008 10:56 am

    Ummmm I really want to het on myspace at work I work 18 hours and don’t really have time for family. Everytime I try to go I get access denied any thin that can get me passed it? I have already asked my boss and he will jus not let me.

Got something to say?





Who is Brian Layman

I am a WordPress expert living in North East Ohio. I am part of the ever expanding Open Source Internet workforce. I am able to stay at home, with my wife and four home schooled kids, while working as the Senior Developer for b5media - a blogging network that has hosted over 300+

I co-host the NEO WordPress Monthly meetup. I am the board chair of our local church. I host and have provided development services for clients such TV personalities Rhett and Link as well as corporations such as Borland International.

In my spare time I try to sneak out, canoe, mountain bike and camp as often as I can. Sometimes I also defend the earth against zombies and aliens, but usually not during the camping trips.

Services Provided

In providing hosting, email, theme and plugin development to my clients, I function as a single point of contact answering to the needs of their expanding sites.

My service portfolio includes but is not limited to WordPress hosting, optimization, theme development and custom plugin creation. Community creation via vBulletin, Ning and BuddyPress and bbpress

I also am well experienced in site conversion, transition and merges. To clarify this, website technologies change and giving up your data is not an option. I have transitioned literally hundreds of sites from one platform to another.

viagra 50 mg indian version of viagra cialis cheapest viagra india online viagra cost comparison viagra for sale without prescription generic tadalafil online buy viagra in korea indian levitra discount cialis online viagra prescription over the counter vardenafil cialis otc cialis no rx cialis 30 mg viagra ranbaxy buy levitra in uk cialis low price tadalafil tablets 10mg cheap viagra fast shipping cheap generic levitra cialis discount cialis 5mg viagra discount prices buy levitra without prescription vardenafil online generic levitra canada viagra professional price cheapest sildenafil citrate indian version of cialis viagra lowest price viagra online prescriptions tadalafil 10mg levitra over the counter levitra prescriptions online buy viagra without a prescription liquid tadalafil citrate buy viagra prescription online tadalafil 20mg india india viagra generic sildenafil citrate for sale vardenafil hcl 10mg cialis discount coupon buy levitra australia viagra over the counter in canada liquid sildenafil tadalafil price comparison viagra cost in india cialis mail order sildenafil sales buy vardenafil cialis offer cheap vardenafil generic cialis no prescription viagra tabs generic indian names viagra price canada vardenafil hcl 20 mg generic viagra without prescription viagra by scilla biotechnologies buy generic cialis free viagra viagra over the counter viagra pills kamagra 100 mg cialis from india tadalafil australia tadalafil 20mg tablets tadalafil soft tabs sildenafil pills viagra no prescription required generic viagra paypal tadalafil online indian viagra cost tadalafil online pharmacy generic soft viagra sildenafil soft tablets viagra generic names buy viagra in ireland levitra without prescription levitra online purchase cialis pill indian tadalafil levitra 5mg cialis cost per pill tadalafil oral jelly sildenafil no prescription vardenafil price generic cialis 10mg cheap cialis no prescription order sildenafil citrate indian generic viagra blue viagra buy cialis usa apcalis 20mg tablets viagra overnight delivery sildenafil india purchase viagra without a prescription viagra prescriptions order viagra without prescription viagra with no prescription levitra for sale purchase viagra canada discount levitra viagra 200mg cheap viagra 100mg cialis overnight delivery buy sildenafil online viagra made in india cialis tabs 10mg viagra indian pharmacy viagra for sale in ireland viagra uk prices buy viagra in europe generic cialis india levitra online viagra for sale india buy viagra in dublin generic cialis soft tabs viagra 50mg cost generic sildenafil 100mg tadalafil generic viagra super active 100 mg kamagra 100mg sildenafil 100 mg tablets cialis no prescription viagra low price online cialis suhagra tablets buy cialis daily use tadalafil sample cialis prices viagra prescription online buy cialis pill kamagra from india cialis online levitra mg vigora india vardenafil 10 mg sildenafil citrate 100mg buy viagra in india buy cialis professional viagra in india buy viagra in singapore generic revatio viagra substitutes sildenafil canada viagra no script cheap kamagra viagra retail price cheap lovegra order viagra uk buy cialis in mexico viagra prescription price purchase cialis online without prescription online cialis prescription ranbaxy caverta buy viagra in hong kong sildenafil price cialis mastercard buy viagra in england viagra mail order canada cialis tablets for sale order cialis cialis soft tabs generic levitra india tadalafil prices cheap sildenafil citrate tablets cialis online prescriptions cialis 5 mg daily levitra prices prescriptions viagra viagra over the counter alternative cialis 20 mg tablets cialis generic india cialis prescribing cialis 20mg daily sildenafil 50 mg viagra drug prices tadalafil generic india cialis sale viagra prices buy viagra 50 mg levitra pharmacy buy viagra generic viagra prescription drug cialis daily cost vardenafil uk viagra soft tabs online buy viagra super active cialis 10mg price 25mg viagra silagra 100mg online viagra prescriptions cialis prescription cheap cialis india revatio 20 mg indian equivalent of viagra tadalafil india viagra capsules cheapest viagra buy cialis without prescription tadalafil overnight cheap tadalafil online purchase viagra online no prescription