0

clicking on this link opens new empty tab, without any url. When I remove the _blank attribute, in the same tab, correct url opens. How this should be done then ?

Thanx a lot

<a  target="_blank" href="javascript:parent.func('/InternalPath/MorePath')" class="someclass">Goal</a>
Julia
  • 1,217
  • 8
  • 23
  • 46

2 Answers2

0

why not modify parent.func() to open link on new tab by itself? add some window.open(url)

It may be quite easy.

Else, you could try to use some callback function

var RunCallbackFunction = function() { }; //reference holder only

Then in your parent (opener), set that function when that child window loads, like this:

//random function you want to call
function myFunc() { alert("I'm a function in the parent window"); }

//to actually open the window..
var win = window.open("window.html");
win.onload = function() { win.RunCallbackFunction = myFunc; };

This assigns the function in your parent to now be the target of that child...and you can point each child to a different function if you wish, they're all independent.

based on Set a callback function to a new window in javascript

Community
  • 1
  • 1
JokinAU
  • 1
  • 1
  • 2
  • i would like not to change this function, it is used on many places, and not each time i need a new tab. Sometimes I want URL to open in same tab. But, im not sure I understand, why this can not work like this, from html ? – Julia Nov 21 '13 at 13:42
  • Trying to throw some light to it... Suppose you have a function that changes the text in a textbox in the same page the function is. Javascript doesn't allow you to open that call in a new window because of THE CONTEXT: there is no textbox in the new page(yet), so how could you reference it? Else, could you share some more code to try to help better? – JokinAU Nov 22 '13 at 11:56
0

If I'm understanding what you're looking for you wish to open the link in a new tab, rather than opening a blank page in a new tab (apologies for not asking this as a comment, I can't comment yet).

If so, try this:

<a  target="_new" href="javascript:parent.func('/InternalPath/MorePath')" class="someclass">Goal</a>
Chris
  • 458
  • 4
  • 17
  • 1
    _blank opens new tab. tab does open, but URL is not there. Tab is empty – Julia Nov 21 '13 at 13:38
  • Right, so wouldn't target="_new" work for you? It's working for me. – Chris Nov 21 '13 at 13:47
  • Shihan, the tab does open, but the URL is not there. Tab has empty url. With _new is the same – Julia Nov 21 '13 at 13:53
  • Yeah, I just did some more research, it's the javascript: part that prevents it. – Chris Nov 21 '13 at 13:54
  • can you be so kind and send me the links to the research ? maybe it says how to handle it ? – Julia Nov 21 '13 at 14:20
  • http://stackoverflow.com/questions/4964130/target-blank-vs-target-new shows that my answer is wrong. It works, but only because of browser support. The rest of my research was simply testing it myself. I haven't gotten it to work. If I do I'll update my answer. – Chris Nov 21 '13 at 16:10