# Embedded form open in parent window from lightbox

**URL:** <https://community.hubspot.com/t/embedded-form-open-in-parent-window-from-lightbox/43720>\
**Category:** CMS Development\
**Tags:** forms\
**Created:** [September 13, 2021, 11:36am UTC](https://community.hubspot.com/t/embedded-form-open-in-parent-window-from-lightbox/43720 "2021-09-13T11:36:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![dsheets74](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dsheets74/32/21752_2.png) [@dsheets74](https://community.hubspot.com/u/dsheets74)\
**Post date:** [September 13, 2021, 11:36am UTC](https://community.hubspot.com/t/embedded-form-open-in-parent-window-from-lightbox/43720/1 "2021-09-13T11:36:24Z")

</div>

Hi everyone,

I’m having trouble with an embedded form not opening the redirect page in a new or parent window. It’s embedded in a different platform than hubspot.

Here is the page - the form is in a lightbox. When you submit it opens in the new window - but it does not redirect to the submit page. The redirect url is set in hubspot - I have tried adding it to the embed script as well though and it does the same thing.

[https://m.gameplanmarketing.ca/form-test/](https://m.gameplanmarketing.ca/form-test/)

```lia-code-sample
<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2.js"></script>
<script>
 hbspt.forms.create({
	region: "na1",
	portalId: "203948",
	formId: "73a77784-c371-449c-a687-02231ad83c15",
 onFormReady: function (form) {
		form.attr('target', '_blank');
	}
});
</script>

```

Any help would be appreciated.

Thanks

---

<div class="post-metadata">

**Author:** ![Teun](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/teun/32/28739_2.png) [@Teun](https://community.hubspot.com/u/Teun)\
**Post date:** [September 13, 2021, 12:37pm UTC](https://community.hubspot.com/t/embedded-form-open-in-parent-window-from-lightbox/43720/2 "2021-09-13T12:37:42Z")

</div>

Hi @dsheets74 ,

I see that the redirectUrl is set correctly to [10 Effective Strategies for Networking Remotely with IT Pros](https://info.gameplanmarketing.ca/10-tips-for-remote-networking-with-it-pros)

You can check the settings of the form in the hidden input **hs\_context** :

```lia-code-sample
{
 "rumScriptExecuteTime":597.5,
 "rumServiceResponseTime":844.1999999992549,
 "rumFormRenderTime":2.7000000029802322,
 "rumTotalRenderTime":91.20000000298023,
 "rumTotalRequestTime":244.59999999776483,
 "lang":"en",
 "embedType":"REGULAR",
 "embedAtTimestamp":"1631535187582",
 "formDefinitionUpdatedAt":"1631532015536",
 "pageUrl":"https://m.gameplanmarketing.ca/form-test/a-10-lightbox.html",
 "source":"FormsNext-static-5.365",
 "timestamp":1631535187586,
 "userAgent":"Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_3) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/93.0.4577.63 Safari/537.36",
 "referrer":"https://m.gameplanmarketing.ca/form-test/",
 "originalEmbedContext":{
 "region":"na1",
 "portalId":"203948",
 "formId":"73a77784-c371-449c-a687-02231ad83c15",
 "target":"#hbspt-form-1631535187765-6867067663",
 "shellId":0,
 "shell":true,
 "pageUrl":"https://m.gameplanmarketing.ca/form-test/a-10-lightbox.html",
 "referrer":"https://m.gameplanmarketing.ca/form-test/"
 },
 "redirectUrl":"https://info.gameplanmarketing.ca/10-tips-for-remote-networking-with-it-pros",
 "formValidity":{
 "firstname":{
 "valid":true
 }
 },
 "domFields":[
 "firstname"
 ],
 "formTarget":"#hbspt-form-1631535187765-6867067663",
 "correlationId":"eb6aed55-ffa8-4d1e-bec6-855adb8a9caf",
 "hutk":"469d5d68a7370944fa029f9c9ca1b33d",
 "useRecaptchaEnterprise":true,
 "isIframe":true
}

```

It seems as if this line is messing with the functionality:

`form.attr('target', '_blank');`

Could you try to remove it just to see if it works without this function?

---

<div class="post-metadata">

**Author:** ![dsheets74](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/dsheets74/32/21752_2.png) [@dsheets74](https://community.hubspot.com/u/dsheets74)\
**Post date:** [September 13, 2021, 2:40pm UTC](https://community.hubspot.com/t/embedded-form-open-in-parent-window-from-lightbox/43720/3 "2021-09-13T14:40:20Z")

</div>

Yes it does work without the form.attr line - it will open the redirect page in the lightbox.

I will try rewriting the function.

---

<div class="post-metadata">

**Author:** ![Teun](https://d10pqhm3lwygmk.cloudfront.net/user_avatar/community.hubspot.com/teun/32/28739_2.png) [@Teun](https://community.hubspot.com/u/Teun)\
**Post date:** [September 13, 2021, 12:48pm UTC](https://community.hubspot.com/t/embedded-form-open-in-parent-window-from-lightbox/43720/4 "2021-09-13T12:48:17Z")

</div>

@dsheets74 If that works, you can rewrite your function to do something like this (instead of target \_blank):

```lia-code-sample
<script charset="utf-8" type="text/javascript" src="//js.hsforms.net/forms/v2.js"></script>
<script>
 hbspt.forms.create({
	region: "na1",
	portalId: "203948",
	formId: "73a77784-c371-449c-a687-02231ad83c15",
 onFormSubmitted: function ($form) {
 window.open(
 'https://info.gameplanmarketing.ca/10-tips-for-remote-networking-with-it-pros',
 '_blank'
 );
	}
 });
</script>

```

If you want to use the redirectUrl set through the form instead of hardcoding the redirect URL, try logging $form to see if it contains the redirectUrl. Otherwise you need the values of the hs\_context input, decode that and retrieve the redirectUrl that way.
