-2
var a = document.getElementById("rusic-modal") || document.createElement("iframe"); a.setAttribute("allow", "fullscreen");
a.src = "https://google.com"; a.id = "rusic-modal";
a.style = "position:fixed;width:100vw;height:100vh;top:0px;left:0px;right:0px;bottom:0px;z-index:2147483647;background-color:white;border:none;"; document.body.appendChild(a);

I can't just run this code on a new about:blank window. I want an about:blank to open, then run the code above to go to google.com

Good Coder
  • 33
  • 4
  • Other than manually pasting it into the console, I doubt this is possible. I don't believe extensions are allowed to execute on `about:...` pages. – DBS May 04 '23 at 10:54
  • checkout https://github.com/Tampermonkey/tampermonkey/issues/312#issuecomment-1529717337 – nosTa May 04 '23 at 10:55
  • 1
    Do you mean you want to open that link in new tab? – ADasGH May 04 '23 at 11:19
  • You can just use `target="_blank"` on a link, is that not possible in your case? [How to open link in a new tab in HTML?](https://stackoverflow.com/questions/17711146/how-to-open-link-in-a-new-tab-in-html) – Peter Krebs May 04 '23 at 11:25
  • @PeterKrebs actually OP is trying to do it via javascript. Not exactly a duplicate. – ADasGH May 04 '23 at 11:27
  • Okay but the OP is already creating tags on the fly. Same with an a tag. Create a tag via JavaScript. Give it an attribute `target` with value `_blank`. Trigger clicking on it. [Or window.open](https://stackoverflow.com/questions/55362152/how-to-open-a-new-tab-in-javascript)? – Peter Krebs May 04 '23 at 11:30
  • Are you sure you don't want to just to **change "new tab" default url** to `google.com`? – Dimava May 04 '23 at 11:31

1 Answers1

1

You can set a link to open in a new tab by using target= '_blank'.

So in your scenario,

var a = document.getElementById("rusic-modal") || document.createElement("iframe"); a.setAttribute("allow", "fullscreen");
a.src = "https://google.com"; a.id = "rusic-modal";
a.target = "_blank";
a.style = "position:fixed;width:100vw;height:100vh;top:0px;left:0px;right:0px;bottom:0px;z-index:2147483647;background-color:white;border:none;";
document.body.appendChild(a);

Hope you find this useful!

ADasGH
  • 487
  • 1
  • 10