0

I am new to javascript and I am using the code below to open a browser window and do some things. However, when I open multiple files simultaneously, it just opens a new tab in the existing browser window, but I want it to open in a new window (preferably incognito mode if possible). Based on my research, I'm thinking I can just modify the if statement, but I'm not sure how.

<html>
   <body onload="window.setTimeout('document.getElementById(\'criimlaunch\').click();', 1000);">

      <script>
         var macroCode = '';
         macroCode += 'PROMPT HELLO!\n';

         function launchMacro()
            {
            try
               {
                  if(!/^(?:chrome|https?|file)/.test(location))
                  {
                     alert('iMacros: Open webpage to run a macro.');
                     return;
                  }

                  var macro = {}; 
                  macro.source = macroCode;
                  macro.name = 'EmbeddedMacro';

                  var evt = document.createEvent('CustomEvent');
                  evt.initCustomEvent('iMacrosRunMacro', true, true, macro);
                  window.dispatchEvent(evt);
               }
            catch(e)
            {
               alert('iMacros Bookmarklet error: '+e.toString());
            };
         }
      </script>

      <a id="criimlaunch" href="javascript:launchMacro();">Launch iMacros</a>

   </body>
</html>
SUMguy
  • 1,505
  • 4
  • 31
  • 61
  • None of that code creates a new window or tab. – robinsax Dec 27 '18 at 06:10
  • Possible duplicate of [Open a URL in a new tab (and not a new window) using JavaScript](https://stackoverflow.com/questions/4907843/open-a-url-in-a-new-tab-and-not-a-new-window-using-javascript) – Toan Lu Dec 27 '18 at 07:58

3 Answers3

2

If you want to open new window you should use

window.open (URL, windowName[, windowFeatures])

I think below links will help you.

Using the window.open method

window.open w3schools

Pallamolla Sai
  • 2,337
  • 1
  • 13
  • 14
0

Chrome extensions with the tabs permission can use the chrome.windows.create method:

chrome.windows.create({"url": url, "incognito": true});

However, to access it, you'll either need to write your own extension or find an existing one which provides a suitable hook

stackoverflow
  • 82
  • 1
  • 1
  • 10
-1

You can try

windows.create({"url": url, "incognito": true});
Noor A Shuvo
  • 2,639
  • 3
  • 23
  • 48