1

I have a function opening a new window, attached to a button:

<button onclick="newWin()">New Window</button>

This works fine but just the first time it is clicked. Following times, even when the opened window has been closed, I have this error:

TypeError: newWin is not a function

This is the JS function:

function newWin() {
       newWindow= window.open('pan/newWin.html', 'Nueva ventana', 'toolbar=yes,location=no,resizable=no,width=600,height=820');}
5
  • That doesn't make any sense. What you've posted should work. There is obviously more to this problem than in your example. Commented Dec 14, 2015 at 17:03
  • 6
    are you sure that inside newWindow=... and not newWin=...? can you provide jsfiddle? Commented Dec 14, 2015 at 17:03
  • That was it. Certainly it is newWin, same name as function. Thank you Commented Dec 14, 2015 at 17:04
  • Please post this as answer to tick you. Commented Dec 14, 2015 at 17:04
  • 1
    Please don’t correct your code in the question, as it invalidates the answers that solve your issue. Commented Dec 14, 2015 at 17:09

2 Answers 2

1

You have two mistake:

  1. try save opened window in variable with same name as function
  2. not use var keyword.

In your case you just redefine global property newWin from function to object.

for solving you can rename it, or just use var keyword: var newWin = window.open(...)

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

Comments

1

Your are assigning some object to function variable.

First time on page load newWin() will be loaded as function. After execution of function you are assigning some value to it .

Hence it is resulting in to error.

Comments

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.