简体   繁体   中英

Open and control new window in KRL/Kynetx

I want to open a new window by clicking on a button (which is injected via Kynetx), but I want this new window to run in the Kynetx sandbox enviornment. This is because the new window will have a button which talks to a REST API, and I want to avoid browser same origin policy. I will also want to modify the DOM of this new window.

//code in Kynetx extension
ruleset a2031x3 {
meta {
    name "Open a new window (SO 12030281)"
    description << >>
    author "Steve Nay"
    logging off
}

dispatch { 

    domain "exampley.com"

    }

global { }

rule first_rule {
    select when pageview ".*" setting ()
    emit <|
        // Open a new window and write some content
        var newContent = 'some content';
        newWin = window.open();
        newWin.document.write(newContent);
    |>;        
 }
}

Please help.

You need to wrap that JavaScript code in an emit block, like this:

ruleset a000x0 {
    meta {
        name "Open a new window (SO 12030281)"
        description << >>
        author "Steve Nay"
        logging off
    }

    dispatch { }

    global { }

    rule first_rule {
        select when pageview ".*" setting ()
        emit <|
            // Open a new window and write some content
            var newContent = 'some content';
            newWin = window.open();
            newWin.document.write(newContent);
        |>;        
    }
}

That will open a popup window like you want, and the write() call succeeds:

弹出窗口,“某些内容”

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM