0

I have the following code for a Chrome extension

Manifest.json:

{
  "name": "Popup_DB",
  "version": "0.0.1",
  "manifest_version": 2,
  "description": "random",
  "browser_action": {
    "default_title": "Alt+C for opening",
    "default_popup": "hello.html"
  },
    "commands": {
      "_execute_browser_action": {
        "suggested_key": {
          "windows": "Alt+C"
        }
      }
    },
  "permissions": [
    "*://*/*",
    "tabs"
  ]
}

Hello.html:

<html>
<head>
    <style type="text/css">
    body {width:780; height:580;}
    </style>
</head>
<body>
    <iframe src= "https://www.bing.com/" width="100%" height="100%" frameborder="0" id="MyFrame">
    </iframe>
</body>
</html>

The website I have mentioned in iframe is a keepsake. Basically, within the popup window, I want to open a page in which all 'Go' links force opening a page in the new tab forcing the popup to close.

Is there a way to edit HTML code so that nothing opens in a new tab so that I can basically do picture-in-picture?

Ansh
  • 175
  • 1
  • 2
  • 13
  • You can have a content script running inside the iframe ([example](https://stackoverflow.com/questions/39901128/content-js-in-iframe-from-chrome-extension-popup)) which will invoke preventDefault on `mousedown` event. – wOxxOm May 14 '18 at 18:57
  • Snippet: Only stops from the link to open, can't stop opening it in a new tab. – Ansh May 14 '18 at 19:18
  • I suggested `mousedown` event, not `click`. Also, you need to investigate how exactly that site is opening the offending URL. If it's window.open(), you'll need to spoof this function in the [page context](https://stackoverflow.com/a/9517879) inside the content script that runs in the iframe. – wOxxOm May 14 '18 at 19:20
  • @wOxxOm The page opens links using target="_blank". Do you mean I have to use mousedown to make all links being forced to open on the same page? Something like: $( "#target" ).mousedown(function() { //code to cause all links to open in same page }); – Ansh May 15 '18 at 03:58
  • Either that or simply remove the target attribute from all links on load. – wOxxOm May 15 '18 at 04:51

0 Answers0