Lucian Bumb Lucian Bumb - 4 months ago 5x
jQuery Question

How to call a Java script function after my app is open in a new tab?

I have a kind of single page application, and in one scenario I need to open my app in a second tab, and the second tab must be open with a specific partial view.

I have this function to open the app in a new tab:

function OpenInNewTab(id) {

var win ="Index","_blank");
//MainMenuClick("CandidateInfo", id) <-- this function I want to call on the new Tab, after loading.

is opening my app in a new tab on the "Home/Index" page, which is ok (half of the task);

Now I want to call
in order to open a specific partial view, inside Index page (in the new tab).

I do not know how to call a function in the new open tab!

Is it possible to tell to the browser to call "
" function in the new tab?

hsh hsh

You can use query string to achieve that, take current partial view id and pass it through like this:

var win ="Index?partialViewId=" + partialViewId,"_blank");

In your SPA global script, search url for that specific key and if it exists call MainMenuClick with the value you've got.this means when the page is loading if a key with the name partialViewId exists, script should select that partial view after page loaded. in order to do that use this function to get any key from url:

function getParameterByName(name, url) {
   if (!url) url = window.location.href;
   name = name.replace(/[\[\]]/g, "\\$&");
   var regex = new RegExp("[?&]" + name + "(=([^&#]*)|&|#|$)"),
       results = regex.exec(url);
   if (!results) return null;
   if (!results[2]) return '';
   return decodeURIComponent(results[2].replace(/\+/g, " "));

and finally get your id like this:

var partialViewId = getParameterByName('partialViewId');
if(partialViewId != null)
    MainMenuClick("CandidateInfo", partialViewId);

hope that helps.