Tutorial: View.attach

View.attach

Attaches a View to a window.

Example

let view;
async function createView() {
    const me = await fin.Window.getCurrent();
    return fin.View.create({ 
        url: 'https://google.com', 
        name: 'viewNameAttach', 
        target: me.identity, 
        bounds: {top: 10, left: 10, width: 200, height: 200} 
    });
}

async function attachView() {
    await createView();
    console.log('View created.');
    const me = await fin.Window.getCurrent();
    view = fin.View.wrapSync({ uuid: me.identity.uuid, name: 'viewNameAttach' });
    const winOption = {
        name:'winOptionName',
        defaultWidth: 300,
        defaultHeight: 300,
        url: 'https://cdn.openfin.co/docs/javascript/stable/tutorial-Window.create.html',
        frame: true,
        autoShow: true
    };
    const newWindow = await fin.Window.create(winOption);
    view.attach(newWindow.identity);
}

attachView()
    .then(() => console.log('View attached to new window.'))
    .catch(err => console.log(err));