Search code examples
javascriptoperawindow.opendocument.write

"error:ReferenceError: Security error: attempted to read protected variable: write" with Opera 11.5 and window.open and document.write


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!


Solution

  • 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.