0

I have postback method in asp.net and after that I want to open new blank page.

I am displaying some message from client side and explicitly clicking a href but that href is not firing.

<a href="../tools/pagename.aspx" target="_blank" id="aProcess"></a>

function DownloadData()
{
   $("#aProcess").click();
}

I want to execute href in new page. window.open() which I do not want to use. I want to open new window. using window.open() as it may blocked by browser sometime. Therefore a href call explicitly I want to trigger.

k-s
  • 2,192
  • 11
  • 39
  • 73

4 Answers4

1

In order to open a new browser window with jquery you can use window.open() method:

window.open(URL,name,specs,replace)

URL: Optional. Specifies the URL of the page to open. If no URL is specified, a new window with about:blank is opened.

name:Optional.Specifies the target attribute or the name of the window.

specs:Optional. A comma-separated list of items.

replace:Optional.Specifies whether the URL creates a new entry or replaces the current entry in the history list(true||false).

to open your page:

$("a#aProcess").click(function(){
    window.open('http://localhost:port/...','_blank');
});
Ramin Omrani
  • 3,673
  • 8
  • 34
  • 60
0

for change current page url:

function DownloadData()
{
   window.location = 'new url';
}

for opening new page:

window.open(url);

This is the only thing you can do if browser settings permit it.

Fortunately!

If it was different i think that will be impossible to surf the web without having tons of popup opened

giammin
  • 18,620
  • 8
  • 71
  • 89
  • Yea, but it will open in same window. I want to open new window. Also do not want to use window.open() as it may blocked. – k-s Feb 08 '13 at 14:40
  • @Keyur then the problem is somewhere else in your code and not related to that function – giammin Feb 08 '13 at 15:42
0

Use this if you want the url to be opened in the current window

document.location.href = 'http://url.com';

If you want the url opened in a new window without using window.open(). You can use

window.showModalDialog("http://url.com",window);
dlock
  • 9,447
  • 9
  • 47
  • 67
  • Yea, but it will open in same window. I want to open new window. Also do not want to use window.open() as it may blocked. – k-s Feb 08 '13 at 14:41
  • I already have popup opened and window.open nor showModaldialog working. – k-s Feb 08 '13 at 14:55
  • 2
    `Window.open` should work on all browsers without problems as long as you are firing it manually ie: button click. But if you run `window.open` in an event that the user has no control over, it will be considered as a popup and will be blocked. So, I really recommend that you explain more about what you are trying to do instead of saying "I don't want to use window.open". – dlock Feb 08 '13 at 15:09
  • Thanks for your help..Yes, you are right. I already have popup opened in IE, I am opening window.open - which can be blocked. So I want to open up new page which sets in href. – k-s Feb 08 '13 at 15:19
  • [window.showModalDialog is deprecated](https://stackoverflow.com/questions/20733962/why-is-window-showmodaldialog-deprecated-what-to-use-instead) – itsmysterybox May 12 '19 at 12:35
0
    $("a#aProcess").click(function(e) {
        e.preventDefault();
        window.open($(this).attr('href'), '_blank');
    });
Mohebifar
  • 3,341
  • 1
  • 24
  • 32