0
newtab = window.open('about:blank','_newtab' );
newtab.location.replace = ('http://www.yahoo.com/')

I need to open a new tab with a different domain. But the following error occured

instance_controller.js:184 Uncaught TypeError: Cannot read property 'location' of undefined

Why this is happening? Please give a solution.

Ismail RBOUH
  • 10,292
  • 2
  • 24
  • 36
akhil viswam
  • 496
  • 9
  • 24

5 Answers5

0

Try this:

newtab = window.open('about:blank', '_newtab');

newtab.location = ('http://www.yahoo.com/');
Hassan Abbas
  • 1,166
  • 20
  • 47
0

I believe this is happening because the window.open function has already executed and detatched itself from the parent scope. Correct me if I'm wrong.

Why not just use window.open("http://www.yahoo.com/", "_blank");?

KO.
  • 173
  • 3
  • 18
0
newtab=window.open('http://www.yahoo.com/','_newtab' );

This will work but it will be blocked by popup blockers.

DunnoHowToCode
  • 531
  • 1
  • 4
  • 14
0

JSFiddledemo

var url = "http://www.example.com";
window.open(url, '_blank');
Mahendra Kulkarni
  • 1,437
  • 2
  • 26
  • 35
0

According to this link: https://developer.mozilla.org/en-US/docs/Web/Security/Same-origin_policy the issue is that you cannot programmatically interact with a page from another domain. You do get a reference back to the window object - but because it is cross domain, you will get a very striped down set of functionality.

As the others have stated, you should just enter the url of the page that you want to load in your popup when you call the window.open function.

Rob Wilson
  • 1,123
  • 1
  • 8
  • 13
  • Then how i meet my requirement?I need to open new domain in a new tab but not without popup blocking@Rob Wilson – akhil viswam Jun 29 '16 at 10:47
  • Ok, that's a different question. I think, ultimately, you are at the mercy of the browser/popup blocker - if they don't want you opening windows, then there will probably be no consistent way to do this cross browser. Here are a couple of links to that question, that may be of help (or may not ;)). http://stackoverflow.com/questions/9514698/bypass-popup-blocker-on-window-open-when-jquery-event-preventdefault-is-set http://stackoverflow.com/questions/2587677/avoid-browser-popup-blockers – Rob Wilson Jun 29 '16 at 10:53
  • also, as suggested on those pages and the mozilla link, you may be able to change the location with: newtab.location = 'http://www.yahoo.com/' but that also may not work across all browsers..... – Rob Wilson Jun 29 '16 at 10:56