0

With the lightning readiness report there is mention that javascript window method won't perform as supposed to in Lightning. Salesforce documentation suggest sforce.one navigation methods to replace certain methods such as

window.location()

. My question is, what are the alternative in terms of

window.close()

.

window.open()

Thanks in advance.

1
  • I came with the same problem. I did not find the correct syntax supported in Lightning.I moved to Lightning Component or going to use style to create popup in VF page. Dec 19, 2018 at 8:59

2 Answers 2

1

Basically, you'd use a modal instead of close/open. See the lightning:overlayLibrary component for methods you can use to display and close a modal.

7
  • Yeah I tought so. Do I have to describe the behaviour of my modal in the controller ? Dec 19, 2018 at 11:48
  • @nyambalakesu You just create a component, and hand the overlay library the component and some optional parameters, it takes care of the rest.
    – sfdcfox
    Dec 19, 2018 at 11:53
  • But how would Visualforce leverage a Lightning modal?
    – Charles T
    Dec 22, 2018 at 16:46
  • @CharlesT Locker Service does not restrict Visualforce, so you'd still use open/close/etc.
    – sfdcfox
    Dec 22, 2018 at 16:54
  • Sorry let me clarify. I believe Overlay Library component communicates with the one.app container in Lightning Experience in order to open modals. But Lightning components embedded in the Visualforce iFrame don't have access to the one.app container. So how would Visualforce be able to leverage that library?
    – Charles T
    Dec 23, 2018 at 7:57
0

Great answer sfdcfox, using modals is definitively the better way to go!

In addition, for some cases, the window methods can be still useful:

  • window.open() and window.location() display a confirmation dialog to ask the user if they would like to navigate away from the current domain. This is in an effort to prevent phishing attacks, e.g. salesforce.com -> saelsforce.com.
  • window.close() should work as expected, just remember that scripts may not close windows that were not opened by them.

I hope this helps!

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .