0

Totally noob question over here, I have this JS code where using only ONE function works perfectly, but adding a second one makes it stop working.

function PSN() {
    var myWindow = window.open("http://sintarjetas.com.ar/forms/psn.html", "Fran", "width=380, height=400");
}
function BLIZ() {
    var myWindow = window.open("http://sintarjetas.com.ar/forms/bliz.html", "Fran", "width=380, height=400");
}
function XLA() {
    var myWindow = window.open("http://sintarjetas.com.ar/forms/xla.html", "Fran", "width=380, height=400");
}
function STEAM() {
    var myWindow = window.open("http://sintarjetas.com.ar/forms/steam.html", "Fran", "width=380, height=400");
}

PSN button works ok when there's only one function written, but as I put 2 or more, all of the links stop working. Is it because of the syntax of this file? Or am I missing something?

6
  • What's the rest of your code that calls these functions? Commented May 6, 2015 at 6:28
  • Must be something else. Defining a new function with a new name doesn't cause previous functions to stop working. Commented May 6, 2015 at 6:28
  • When you trigger PSN, it pops open a window, when you trigger BLIZ it then replaces the content of the PSN window instead of opening a new one - are you checking the existing window? Commented May 6, 2015 at 6:36
  • Which browser you are checking on??? Commented May 6, 2015 at 6:37
  • Here's a jsfiddle - works fine for us: jsfiddle.net/5pxxoreg (apart from the broken link - but the pop ups work) Commented May 6, 2015 at 6:39

1 Answer 1

1

you don't need multiple function to open pop up, you can just create single function and pass the url as param

function popUp(url) {
   return window.open(url, "Fran", "width=380, height=400");
}

Note: Put your functions block in <header> of page then try. here is working fiddle

Update : Since all window names are same Fran you will need to close the opened window first before opening other. currently it will open the url in previously opened window.

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

7 Comments

I've already made 91 functions with their corresponding onclick's in the html file, isn't there another way to fix it? PS: F12 console is returning "Uncaught ReferenceError: PSN is not defined"
<a href="javascript:void(0)" onclick="PSN()" title="Read More" class="btn btn-inverse btn-normal btn-primary btn-from-left"><span data-hover="Ver más">Ver más</span></a> Edit: Giving all windows the same name was a solution to stop the user from opening 2 forms at the same time.
make sure your js is before your html code see the updated answer
It already is, the js script is one of the first things in the header. This might be helpful, check your fiddle again, making a second link stops it from working. jsfiddle.net/wcxc649r/2
fiddle is working, there was a type in function call BLITZ, yo have defined it as BLIZ
|

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.