Skip to content

Commit 5f4e022

Browse files
committed
Add support for giving name and features to the new window
1 parent 85cdbed commit 5f4e022

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

README.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,10 @@ Supported props are:
4242
- onMessage
4343

4444
Additional props are:
45-
- `newWindow`: this will open the source in a new window.
46-
Useful when your target has X-Frame-Options or a no-CORS policy.
45+
- `newWindow`: (*boolean*|*{ name: string, features: string}*)
46+
This will open the source in a new window, optionally giving it an [internal name and custom features](https://developer.mozilla.org/en-US/docs/Web/API/Window/open).
47+
By default, the name is `webview` and there are no features set.
48+
This is useful when your target has X-Frame-Options or a no-CORS policy.
4749
It currently only supports a `source` prop with a `method` set to `POST`.
4850
Please feel free to do a PR to support more request types!
4951

src/index.js

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ export default class extends Component {
1414
if (!source.method) return;
1515

1616
if (newWindow) {
17-
this.handleSourceInNewWindow(source);
17+
this.handleSourceInNewWindow(source, newWindow);
1818
} else {
1919
this.handleSourceInIFrame(source);
2020
}
@@ -28,7 +28,7 @@ export default class extends Component {
2828
.then(html => this.setState({ html: `<base href="${baseUrl}" />` + html }));
2929
};
3030

31-
handleSourceInNewWindow = source => {
31+
handleSourceInNewWindow = (source, newWindow) => {
3232
if (source.method === 'POST') {
3333
const contentType = source.headers['Content-Type'];
3434
let body = '';
@@ -48,7 +48,9 @@ export default class extends Component {
4848
Qs.stringify({
4949
uri: source.uri,
5050
body: JSON.stringify(body),
51-
})
51+
}),
52+
newWindow.name || 'webview',
53+
newWindow.features || undefined
5254
);
5355
} else {
5456
console.warn(

0 commit comments

Comments
 (0)