1
votes

How to open a popup window in USD hosted control ?

Javascript code:

<script>
    function basicPopup(url) {
popupWindow = window.open(url,'popUpWindow','height=300,width=700,left=50,top=50,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no, status=yes')
    }

</script>
<a href="https://www.google.com" onclick="basicPopup(this.href);return false">Open a popup window</a>

USD Window navigation rules

Route Type - Popup, Action - Show Outside , Destination - Tab

Hosting Type: Edge Process/Chrome Process.

Issue: When launching the above JS snippet in a browser, it worked as expected (popup opens with given dimensions and child window able to communicate to parent window with Post message ) whereas the same code integrated with USD, the popup launches in new tab and newly opened window unable to communicate to parent window (window.open() returns null)

Any ideas as to what I'm missing?

2

2 Answers

1
votes

If you let USD host all of your browser processes and unify your browser types, you may be able to access your parent windows as desired.

Create a "destination" / "child" hosted control that can receive your target navigation. Make all browsers Chrome, and if you can't do that for whatever reason, hopefully you can make them all Edge instead. In your Window Navigation Rule, instead of Show Outside, use the action Route Window, and set the Target Tab to the new child browser hosted control. Put the child browser on FloatingPanel if you prefer not to host it as a MainPanel tab.

Also, not to be redundant, but having noticed your "Chrome/Edge" hybrid hosting summary above, I would suggest doing as much as possible to eliminate the hosting of multiple browser types throughout your configuration(s). I would assume that a USD-hosted browser handing off to a "Windows hosted" browser could complicate (prevent?) your ability to find the parent window, even if the browser type inside and outside of USD are the same. To my knowledge, USD and Windows use different versions of Edge (USD has yet to integrate the new Edge, and it might never) and USD manages its own Chromium instances. I assume "Show Outside" in Chrome does not launch a new CEF process from your USD application folder, but rather just hands off to Windows, which then invokes the Chrome stand-alone application (if it is your OS default browser). There may(?) be value in testing various combinations of browser types here, if you are committed to the "Show Outside" paradigm for whatever reason.

0
votes

It is possible they do not allow a popup at all, like here at SO in the snippets.

You can look in the console.

Here is a version with more info - NOTE this version does not pop anything at SO due to sandboxing

NOTE You cannot access the contents in the popup or the parent from the popup if the contents are from different origins

document.getElementById("popupDiv").addEventListener("click", function(e) {
  const tgt = e.target.closest("a");
  if (tgt && tgt.classList.contains("popup")) {
    const popupWindow = window.open(tgt.href, tgt.target, 'height=300,width=700,left=50,top=50,resizable,scrollbars,toolbar,status');
    if (popupWindow) {
      console.log("Popup allowed");
      e.preventDefault(); // cancel the actual link
    } else console.log("Not allowed to pop, target used instead")
  }
})
<div id="popupDiv">
  <a href="https://www.google.com" target="popopWindow" class="popup">Open a popup window</a>
</div>