# Dynamic link creation opening new window not working

**URL:** <https://forum.wixstudio.com/t/dynamic-link-creation-opening-new-window-not-working/55491>\
**Category:** Ask the community\
**Tags:** wix-members-area, question, code, cms\
**Created:** [January 16, 2024, 10:46pm UTC](https://forum.wixstudio.com/t/dynamic-link-creation-opening-new-window-not-working/55491 "2024-01-16T22:46:14Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Graham\_Jacobs](https://avatars.discourse-cdn.com/v4/letter/g/49beb7/32.png) [@Graham\_Jacobs](https://forum.wixstudio.com/u/Graham_Jacobs)\
**Post date:** [January 16, 2024, 10:46pm UTC](https://forum.wixstudio.com/t/dynamic-link-creation-opening-new-window-not-working/55491/1 "2024-01-16T22:46:15Z")

</div>

I have a page in the members area which takes the logged in user’s email, uses it to look up a link in the CMS. This link I then want to open in a new tab. Here is my code (I also assign a couple of text fields with the CMS data just to prove connection works). The issue lies in $w(‘#button3’).link = entry.link - I was hoping this would open the link:

import wixUsers from ‘wix-users’;  
import wixData from ‘wix-data’;

$w.onReady(function () {

```
async function button3_click(event) {
    let user = wixUsers.currentUser;
    let userEmail;

    if (user.loggedIn) {
        try {
            // Get the user's email using async/await
            userEmail = await user.getEmail();
            console.log('user email', userEmail);
            $w('#text51').text = userEmail;

            // Query your CMS collection based on the user's email
            wixData.query('ExceldocumentLinks')
                .eq('email', userEmail)
                .find()
                .then(results => {
                    // Check if any entries were found
                    if (results.items.length > 0) {
                        // Access the first entry
                        const entry = results.items[0];

                        // Now you can use the entry data as needed
                        console.log('CMS Entry:', entry);
                        $w('#text52').text = entry.link; 
                        $w('#button3').link = entry.link;
	
                    } else {
                        // Handle the case where no entry was found for the constant email value
                        console.error('No CMS entry found for the constant email value');
                    }
                })
                .catch(error => {
                    // Handle errors during the query
                    console.error('Error querying CMS:', error);
                });
        } catch (error) {
            console.error('Error getting user email:', error);
        }
    } else {
        // Handle the case where the user is not logged in
        console.error('User not logged in');
    }
}

// Assign the click event handler to the button
$w('#button3').onClick(button3_click);

```

});

I tried wixlocation but I believe this isn’t approprate in this case. I also tried custom element but couldn’t find any specific guidance or resources to this type of request (I am relativey new to Velo so learning as I go).

Any help or links would be much appreciated.

---

<div class="post-metadata">

**Author:** ![thomasj](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/thomasj/32/30791_2.png) [@thomasj](https://forum.wixstudio.com/u/thomasj)\
**Post date:** [January 17, 2024, 6:16pm UTC](https://forum.wixstudio.com/t/dynamic-link-creation-opening-new-window-not-working/55491/2 "2024-01-17T18:16:26Z")

</div>

[$w(‘#button’).link](https://www.wix.com/velo/reference/$w/button/link) is a great way to set a button to open a external link on click. You can also set .[target](https://www.wix.com/velo/reference/$w/button/target) to control the behavior of where the link opens.

Does the `#text52` element display the intended external url?

If so, does the string use the format below?

> - `http(s)://<url>`: an external web address

_Note: The http(s):// is required to be recognized as a external url_

---

<div class="post-metadata">

**Author:** ![Graham\_Jacobs](https://avatars.discourse-cdn.com/v4/letter/g/49beb7/32.png) [@Graham\_Jacobs](https://forum.wixstudio.com/u/Graham_Jacobs)\
**Post date:** [January 18, 2024, 9:42am UTC](https://forum.wixstudio.com/t/dynamic-link-creation-opening-new-window-not-working/55491/3 "2024-01-18T09:42:54Z")

</div>

Hi Thomas, thanks for your reply. Yes, `#text52` element does display the intended external url and the string used in is in that format. The window doesn’t even attamept to open if that helps too?

Thank you

---

<div class="post-metadata">

**Author:** ![Graham\_Jacobs](https://avatars.discourse-cdn.com/v4/letter/g/49beb7/32.png) [@Graham\_Jacobs](https://forum.wixstudio.com/u/Graham_Jacobs)\
**Post date:** [January 18, 2024, 9:46am UTC](https://forum.wixstudio.com/t/dynamic-link-creation-opening-new-window-not-working/55491/4 "2024-01-18T09:46:51Z")

</div>

@thomasj It has now started working. The link I was using as a test had a redirect attachted to it so I changed it to a link that did not and it worked. Thank you for your help, I was looking in the wrong place!
