Ask coding questions

← Back to all posts
window.open isn't working
MikeJMS8910 (234)

So if you test out my button you can see that the go to button isn't working. It's supposed to open a link in a new tab but for this, it just breaks the page. If you manually put in the open() function though it will log the link that should open many times but never actually open it. Can someone tell me why this isn't working?

Answered by Baconman321 (1104) [earned 5 cycles]
View Answer
Comments
hotnewtop
Pythonier (316)

You have a typo, I'm not sure if this is the problem though.

consoel.log("Window type is good");
Pythonier (316)

I also don't think you ever use window.open(), only assign it.

Baconman321 (1104)

@Pythonier He doesn't assign it, he assigns a variable with the value of it.

MikeJMS8910 (234)

@Pythonier good catch with the console

MikeJMS8910 (234)

@Baconman321 how would I run it
I tested out just putting openWindow; but it still doesn't work

Baconman321 (1104)

@MikeJMS8910 This because open() is also considered as window.open(). You are colliding with the window.open() function. What you should do is attack a listener in your JavaScript instead of using an inline onclick attribute. Put the script tag right before the bottom of webpage. I forked your repl and you can see the changes I made here: https://repl.it/@Baconman321/RandomReplGenerator#index.html.

MikeJMS8910 (234)

@Baconman321 thank you so much that makes a lot of sence

MikeJMS8910 (234)

@Baconman321 also, I am needing to add some more projects to this so are there any that you would like me to add that could be yours

Baconman321 (1104)

@MikeJMS8910 Is it ok if I delete my fork now? Are you done with it?

MikeJMS8910 (234)

@Baconman321 ok I just added stargaze because I'm mainly looking to add games and stuff like that, tell me if there are any games you have you want me to add

Baconman321 (1104)

@MikeJMS8910 Not really..

Stargaze is more of a recreational activity, but whatever.

I'm eventually going to remake it because it is very slow.

MikeJMS8910 (234)

@Baconman321 ok. I saw your portfolio project and it looked really cool. Do you think you can help me out with some CSS with my project

Baconman321 (1104)

@MikeJMS8910 I'm not that good at CSS, you'd be better off working with lilykhan or 19wintersp.

I'm not a good designer because a) I don't practice and b) visualization for me is hard.

Baconman321 (1104)

You aren't specifying a URL when you open it.

Also, it's a good idea to put window before the method, like so: window.open().

Again, make sure you pass in the URL as an argument in window.open, otherwise it will open a blank page (or none at all).

MikeJMS8910 (234)

@Baconman321 I do have the URL it is inside the variable

IOP3 (847)

Everything seems to be working fine

MikeJMS8910 (234)

@IcingHackz really so it goes to the page when you press 'go to'

IOP3 (847)

@MikeJMS8910 no, it just shows a white page

MikeJMS8910 (234)

@IcingHackz yea thats not supposed to happen