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>
-
None of that code creates a new window or tab.robinsax– robinsax2018年12月27日 06:10:04 +00:00Commented Dec 27, 2018 at 6:10
-
Possible duplicate of Open a URL in a new tab (and not a new window) using JavaScriptToan Lu– Toan Lu2018年12月27日 07:58:21 +00:00Commented Dec 27, 2018 at 7:58
3 Answers 3
If you want to open new window you should use
window.open (URL, windowName[, windowFeatures])
I think below links will help you.
Comments
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
Comments
You can try
windows.create({"url": url, "incognito": true});