1

How can i add custom attribute to window object using javascript. I am doing it like:

var mypopupWindow = window.open(url);
mypopupWindow.myProperty = window;

But myProperty remains undefined when i try to access it from mypopupWindow, i am using IE.9.

2 Answers 2

2

Well, this works for me in Chrome

var originWindow = this;
var popupWindow = window.open()
popupWindow.a = "b"
originWindow.a = "c"
  popupWindow.setTimeout(function () {
    alert(this.a) //b

  },500);

If i run this code on JSBin, the alert displays "b".

So the window.open's returned window's propertie is assigned fine.

You can of course open the console in the new Window in chrome and the Window has a propertie a with the value "b"

Heres a JSBin

Screenshot

Sign up to request clarification or add additional context in comments.

Comments

1

I don't think you can set these attributes reliably on the window object itself, but you could set them on the windows document object instead.

1 Comment

As I said, we can't set them reliably, but thanks for the downvote. The reason is that IE9 is opening the window asynchronously, so it is trying to set the value of the myProperty attribute before the window has opened.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.