3

I am having an issue with window.open that only occurs with Opera (version 11.5).

function openpageopera()
{
  var w = window.open("","_blank");
  try
  {
    w.document.write("<p>hello</p>world");
    w.document.close();
  }
  catch(err)
  {
    alert("error:" + err);
  }
}

Now, it works flawlessly when I execute this function after the page has loaded, ergo:

$(document).ready(function() {
  openpageopera();
});

And it also work if I'm opening a URL like google, yahoo, or even a webpage from my web server.

However, when I attach it to an onclick event, like on an HTML button, it fails.

<input type="button" value="Fails" onclick="openpageopera();">

What fails specifically? Well, the page does open but it's blank. document.write is NOT working. The catch noted an error of:

error:ReferenceError: Security error: attempted to read protected variable: write

I don't understand why executing this on the html button raises a security error. Why is this occurring and how can I resolve it?

Thank you very much for your help!

user717236
  • 4,959
  • 19
  • 66
  • 102
  • 1
    Doesn't fail for me(opera 11.51) – Dr.Molle Sep 28 '11 at 18:16
  • Can you paste your full code so I can test it? – user717236 Sep 28 '11 at 18:25
  • 1
    Her it is: http://jsfiddle.net/doktormolle/EePex/ – Dr.Molle Sep 28 '11 at 18:37
  • Yes, your code does work. Odd. I copied all the content in my document and pasted it into a new document and renamed the file. This new document worked fine, yet it the code is exactly the same. Then, I cleared all private data and tried both the original and the duplicate and they both worked fine. That is odd, because I made sure to clear the cache (shift or ctrl refresh). It must've been a caching issue, though, I think, I'm not quite sure. Thank you for your help. – user717236 Sep 28 '11 at 19:07
  • I'm getting the same message when trying to start phpmyadmin (opera version 11.52)... –  Oct 27 '11 at 13:32

2 Answers2

4

If there is code somewhere setting document.domain it might change the parent page's security context. (This also happens if document.domain is set to its current value.) When you open "" or about:blank it should inherit the parent's security context and document.write() should work - but I know Opera had some bugs in the past where setting document.domain would cause problems when working with empty popups. I believe those bugs are fixed in 11.50, but it seems as if you ran into a similar issue. Do avoid setting document.domain if you can..

If you see this problem occur again, please let me know and preferably let me see the full code. I'd love to nail this bug in every incarnation..

BTW, keep in mind that User JS, extensions, and even JS triggered from plugins might also mess around with document.domain, so try to disable anything that might interfere.

hallvors
  • 6,069
  • 1
  • 25
  • 43
  • Thank you. I am not setting document.domain. I am using jQuery, via CDN; so, unless they are manipulating it, I am not using it at all. – user717236 Oct 03 '11 at 16:47
  • In that case - and if the problem is indeed gone after clearing private data - you're probably right that it was some issue with the cache. I have never seen this myself and know very little about how the cache data is organised, but perhaps an error in the cache table can make Opera apply wrong security context for a page? this is extremely weird.. :-/ – hallvors Oct 03 '11 at 21:19
1

I ended clearing all private data in the Opera browser and it worked. However, every time I loaded the page, I made sure to press shift or ctrl refresh to clear the cache. Either it was a cache issue or something else entirely.

user717236
  • 4,959
  • 19
  • 66
  • 102