Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I open a new window using jQuery?

Tags:

jquery

I have the following two ways suggested to me.

window.location.href = '/Administration/Notes/Create?dsValue=a&selectAnswer=b';
$.get("/Administration/Notes/Create", { dsValue: dsValue, selectedAnswer: answer });

Are these methods the same? Which one would be the best for me to use and what's the difference between the two?

like image 335
Samantha J T Star Avatar asked Nov 10 '11 06:11

Samantha J T Star


People also ask

How do I open a new window?

To open a new window, use a keyboard shortcut: Windows & Linux: Ctrl + n. Mac: ⌘ + n.

How do I open a new window in HTML?

The href attribute set to the URL of the page you want to link to. The target attribute set to _blank , which tells the browser to open the link in a new tab/window, depending on the browser's settings. The rel attribute set to noreferrer noopener to prevent possible malicious attacks from the pages you link to.


2 Answers

This works:

myWindow = window.open('http://www.yahoo.com','myWindow', "width=200, height=200");
like image 168
chuckfinley Avatar answered Sep 20 '22 22:09

chuckfinley


It's not really something you need jQuery to do. There is a very simple plain old javascript method for doing this:

window.open('http://www.google.com','GoogleWindow', 'width=800, height=600');

That's it.

The first arg is the url, the second is the name of the window, this should be specified because IE will throw a fit about trying to use window.opener later if there was no window name specified (just a little FYI), and the last two params are width/height.

EDIT: Full specification can be found in the link mmmshuddup provided.

like image 31
Matthew Cox Avatar answered Sep 20 '22 22:09

Matthew Cox