pass a JQUERY value to window.open() function

Asked

Viewed 787 times

2

How can I recover a value that comes from a request via JQUERY to a database and put that value into a window.open function();

JQUERY

$(document).on("click", ".modal",  function () {
 var key  = $(this).data('numero');

 var url = 'http://www.exemplo.com&n='; 

 window.open(url, key);
});

If the value returned was 1000 the code should form the following url:

http://www.exemplo.com&n=1000

  • You just want to attach the value in the URL, this? var url = 'http://www.exemplo.com?n=' + key; window.open(url);

  • That’s right, it worked perfectly here!

1 answer

4


Since you want to attach the value in the URL, which is just a string, do a simple concatenation:

var url = 'http://www.exemplo.com?n=' + key;
window.open(url)

The part of the url to pass parameters starts with ? and not with &. The & is to separate key/value pairs.

Browser other questions tagged

You are not signed in. Login or sign up in order to post.