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>
asked Dec 27, 2018 at 6:07
2

3 Answers 3

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

answered Dec 27, 2018 at 6:17
Sign up to request clarification or add additional context in comments.

Comments

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

answered Dec 27, 2018 at 6:11

Comments

-1

You can try

windows.create({"url": url, "incognito": true});
answered Dec 27, 2018 at 6:12

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.