function readOnly(count){ }
Starting November 20, the site will be set to read-only. On December 4, 2023,
forum discussions will move to the Trailblazer Community.
+ Start a Discussion
DiamundoDiamundo 

Javascript window.open() or SLDS Modal... I can't get either to work.

Hi there,

I am trying to create two popup windows. One contains an html page (dynamically created) as preview. The other is the bare html code, shown when the user wants to export the page.

The problem with the javascript popup window:
var mywindow = window.open("", "_blank" /* the rest of the arguments go here*/ );
mywindow.document.write("<p>some text</p>");
mywindow.close();

The problem with the above code is that it crashes on the second line, saying it doesn't know document.write.
If I comment out the second line, I see a window appearing very briefly before correctly dissapearing again.

The problem with modals, is that I simply cannot get them to work.
I can get them to apear (on init, not usefull either), but I cannot get them to hide either on clicking a button or on init.
(No code supplied because tried so many variations I don't know where to start, I guess if I had to choose the SLDS website's example).

Any advice on how to solve either problem?
(If I can solve both tasks with one type of popup I'm absolutely fine with using one method only.)

Thanks!

Best Answer chosen by Diamundo
DiamundoDiamundo
https://github.com/salesforce-ux/design-system/issues/335#issuecomment-256882756

see the comment on my issue on Github. There is the workaround.
It involves adding and removing classes to make the modal appear and dissapear.

All Answers

DiamundoDiamundo
Might be useful to say: I'm working with lightning components.
sfdcMonkey.comsfdcMonkey.com
Diamundo can you share your component code where you use slds MODAL
thanks
DiamundoDiamundo
<aura:component >
    <aura:handler name="init" value="{!this}" action="{!c.doInit}" />

    <div class="slds-grid slds-p-vertical--small">
               
        <div class="slds-p-horizontal--small">
            <lightning:button variant="brand" label="Save" onclick="{!c.save}" />
            <!-- No save icon, so for now we have this button. -->
        </div>

        <div class="slds-p-horizontal--small">
            <button class="slds-button" onclick="{!c.export}">
                <lightning:icon iconName="action:share" size="medium" alternativeText="Export" />
            </button>
            
            <!--
				<lightning:button variant="brand" label="Export" onclick="{!c.export}" />
			-->
        </div>
        
    </div>
    
    <div role="dialog" tabindex="-1" aria-labelledby="header43" class="slds-modal slds-fade-in-open">
        <div class="slds-modal__container">
            <div class="slds-modal__header">
                <button class="slds-button slds-modal__close slds-button--icon-inverse">

<!-- 
SVG Doesn't work, missing component or something. 
That's no biggie though. I don't think I'm keeping the button.

                    <svg aria-hidden="true" class="slds-button__icon slds-button__icon--large">
                        <use xlink:href="/assets/icons/utility-sprite/svg/symbols.svg#close"></use>
                    </svg>
-->
                    <span class="slds-assistive-text">Close</span>
                </button>
                <h2 id="header43" class="slds-text-heading--medium">Modal Header</h2>
            </div>
            <div class="slds-modal__content slds-p-around--medium">
                <div>
					HERE COMES SOME DYNAMICALLY CREATED TEXT                    
                </div>
            </div>
            <div class="slds-modal__footer">
                <button class="slds-button slds-button--neutral">Cancel</button>
                <button class="slds-button slds-button--brand">Save</button>
            </div>
        </div>
    </div>
    <div class="slds-backdrop slds-backdrop--open"></div>
    
</aura:component>

The above code is a snippet with some buttons (you see two, but there's a lot more, but to keep the code clean I removed the others) embedded some layers in my app.

When I load it, the modal springs to life and I can't get it to go away.
I've tried component.find()-ing the div by using its label 'header43', I've tried adding an auraID and finding that, and then setting aira-hidden to true, but nothing would help - I couldn't get the modal to go away...

I put the modal here as the button you can see here (Export) is the one that's going to be activating the modal and then filling it, but if it has to go somewhere else I don't mind, I then will just send an event to the component where it's located and that will do the rest.
 
DiamundoDiamundo
The problem is also that I can't find any good examples (or examples at all) on how to show/hide the modal. My other intention is to put a textarea field in the modal and filling that with dynamically generated text, autofocus on that and let the user CTRL+A CTRL+C copy it instantly, but I'll figure that one out on my own, I don't think that's as hard as this issue :)
DiamundoDiamundo
https://github.com/salesforce-ux/design-system/issues/335#issuecomment-256882756

see the comment on my issue on Github. There is the workaround.
It involves adding and removing classes to make the modal appear and dissapear.
This was selected as the best answer