Skip to content

Commit

Permalink
Add support for giving name and features to the new window
Browse files Browse the repository at this point in the history
  • Loading branch information
Minishlink committed Oct 15, 2017
1 parent 85cdbed commit 5f4e022
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 5 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,10 @@ Supported props are:
- onMessage

Additional props are:
- `newWindow`: this will open the source in a new window.
Useful when your target has X-Frame-Options or a no-CORS policy.
- `newWindow`: (*boolean*|*{ name: string, features: string}*)
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).
By default, the name is `webview` and there are no features set.
This is useful when your target has X-Frame-Options or a no-CORS policy.
It currently only supports a `source` prop with a `method` set to `POST`.
Please feel free to do a PR to support more request types!

Expand Down
8 changes: 5 additions & 3 deletions src/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ export default class extends Component {
if (!source.method) return;

if (newWindow) {
this.handleSourceInNewWindow(source);
this.handleSourceInNewWindow(source, newWindow);
} else {
this.handleSourceInIFrame(source);
}
Expand All @@ -28,7 +28,7 @@ export default class extends Component {
.then(html => this.setState({ html: `<base href="${baseUrl}" />` + html }));
};

handleSourceInNewWindow = source => {
handleSourceInNewWindow = (source, newWindow) => {
if (source.method === 'POST') {
const contentType = source.headers['Content-Type'];
let body = '';
Expand All @@ -48,7 +48,9 @@ export default class extends Component {
Qs.stringify({
uri: source.uri,
body: JSON.stringify(body),
})
}),
newWindow.name || 'webview',
newWindow.features || undefined
);
} else {
console.warn(
Expand Down

0 comments on commit 5f4e022

Please sign in to comment.