# Wix Location - to an internal anchor, dynamic pages

**URL:** <https://forum.wixstudio.com/t/wix-location-to-an-internal-anchor-dynamic-pages/35669>\
**Category:** Ask the community\
**Tags:** question, code\
**Created:** [May 3, 2018, 8:48pm UTC](https://forum.wixstudio.com/t/wix-location-to-an-internal-anchor-dynamic-pages/35669 "2018-05-03T20:48:08Z")\
**Posts on this page:** 13\
**Page:** 1

<div class="post-metadata">

**Author:** ![stephenmccall](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/stephenmccall/32/1773_2.png) [@stephenmccall](https://forum.wixstudio.com/u/stephenmccall)\
**Post date:** [May 3, 2018, 8:48pm UTC](https://forum.wixstudio.com/t/wix-location-to-an-internal-anchor-dynamic-pages/35669/1 "2018-05-03T20:48:08Z")

</div>

Hi,

I’m trying to get a button on a dynamic product page to transfer to an item page anchor, I know I need to use wix-location and scrollTo() but must admit, I’m finding it a little tough to work out.  
If the user clicks on the calendar, they will then be directed to the new page, but then it will scroll to the anchor of that dynamic page, showing the dates.  
Do I need to use wix Location? or can i just link it to the dataset, then once on the new page use a scrollTo function on the new page?

---

<div class="post-metadata">

**Author:** ![doron-alkalay](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/doron-alkalay/32/2887_2.png) [@doron-alkalay](https://forum.wixstudio.com/u/doron-alkalay)\
**Post date:** [May 7, 2018, 12:43pm UTC](https://forum.wixstudio.com/t/wix-location-to-an-internal-anchor-dynamic-pages/35669/2 "2018-05-07T12:43:12Z")

</div>

Hi Stephen!

Please explain what you’re trying to achieve and share a link to your site so one of us (Wix workers) could look into your site.

It is possible to link a button to an anchor on a dynamic page but you’ll have to provide an item that the dynamic page belongs to.

You could also use a [wixLocation.query](https://www.wix.com/code/reference/wix-location.html#query) to specify where you want the page to go  
(including anchors by using ‘?’ in the url).

Best of luck!  
Doron. 🙂

---

<div class="post-metadata">

**Author:** ![stephenmccall](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/stephenmccall/32/1773_2.png) [@stephenmccall](https://forum.wixstudio.com/u/stephenmccall)\
**Post date:** [May 7, 2018, 2:32pm UTC](https://forum.wixstudio.com/t/wix-location-to-an-internal-anchor-dynamic-pages/35669/3 "2018-05-07T14:32:06Z")

</div>

Hi Doron,

Thank you for your reply, the page is [https://www.scottishrockandwater.com/courses/Scrambling](https://www.scottishrockandwater.com/courses/Scrambling)

![](https://us1.discourse-cdn.com/wix/original/3X/1/0/10bd7246dd5b2cb1ae1685eea60b8f8853e51e29.png)  
which will have the above icon, I’m looking for it to be directed to the anchor on a dynamic page such as [https://www.scottishrockandwater.com/Courses/Scrambling/Skye-Classic-Scrambling](https://www.scottishrockandwater.com/Courses/Scrambling/Skye-Classic-Scrambling)  
The anchor is above this picture

 ![](https://us1.discourse-cdn.com/wix/original/3X/f/3/f39093a78ed16b7ca4288ff852ebffc690140df1.png)

I am having trouble getting the link to go to a dynamic page, regardless of the scrollto function at the moment

```javascript
import wixLocation from 'wix-location';

export function calendaricon_click(event, $w) {
	wixLocation.to("/Courses/Courses-category/Title");
}

```

I know that the “/Courses/Courses-category/Title” is wrong as I can get it to work to direct to a standard page, but I’m finding the API reference a little confusing to be able to direct to an internal dynamic page.

Many thanks for your help

Stephen

---

<div class="post-metadata">

**Author:** ![doron-alkalay](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/doron-alkalay/32/2887_2.png) [@doron-alkalay](https://forum.wixstudio.com/u/doron-alkalay)\
**Post date:** [May 10, 2018, 1:32pm UTC](https://forum.wixstudio.com/t/wix-location-to-an-internal-anchor-dynamic-pages/35669/4 "2018-05-10T13:32:51Z")

</div>

Hi Stephen!

First of all I suggest you to change in your dynamic page settings the URL path from ‘/title’ to ‘/ID’ as shown here:

 ![](https://us1.discourse-cdn.com/wix/original/3X/9/1/91392068e34201c44266f7c71bfe87db7137d68b.png)  
The ‘ID’ field is a unique field that is generated for every item thus directing you always to the dynamic page according to the ID of the item.

 ![](https://us1.discourse-cdn.com/wix/original/3X/d/2/d21795e2f95caddf6fee06fbffb943477774d097.png)  
As for directing to the anchor, use the [wixLocation.query](https://www.wix.com/code/reference/wix-location.html#query) to determine **where** in the page the user will be directed upon loading.  
In the first page, in the button’s function you should assign a ‘key’ that will mark the query and be included in the sent url.  
Example: ['? **a=1**'] the ‘?’ starts the query and ‘a=1’ is the mark/key.

```javascript
import wixLocation from 'wix-location';
//...
//...
export function button1_click(event, $w) {
	wixLocation.to(`/Courses/Courses-category/${ID}?a=1`);
}

```

In the onReady( ) function of the target page use a query to ‘search’ in the url for ‘special directions’ if they exist (your ‘a=1’), and then act accordingly to what you find and need.  
its going to look something like that:

```javascript
import wixLocation from 'wix-location';
//...
//...
$w.onReady(function () {
	let query = wixLocation.query;
	if(query.a == 1){
           $w("#anchor1").scrollTo();
	}
}); 

```

Thats pretty much it.

Hope it helps.  
Best of luck!

Doron. 🙂

---

<div class="post-metadata">

**Author:** ![stephenmccall](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/stephenmccall/32/1773_2.png) [@stephenmccall](https://forum.wixstudio.com/u/stephenmccall)\
**Post date:** [May 12, 2018, 10:15am UTC](https://forum.wixstudio.com/t/wix-location-to-an-internal-anchor-dynamic-pages/35669/5 "2018-05-12T10:15:53Z")

</div>

Hi Doron!

Thank you for the detailed response 🙂 It’s much appreciated.

I have a question about the ‘ID’, if this is changed, then how will the URL display?

Also, the code (thank you for explaining, learning lots from you guys!) it has an error

![](https://us1.discourse-cdn.com/wix/original/3X/4/6/46f91612377d285201b2ed98d8893b56fc18a310.png)  
I have tried playing around with the ${ID} but with no success… any ideas?

Thank you for your help

Stephen

---

<div class="post-metadata">

**Author:** ![doron-alkalay](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/doron-alkalay/32/2887_2.png) [@doron-alkalay](https://forum.wixstudio.com/u/doron-alkalay)\
**Post date:** [May 13, 2018, 8:37am UTC](https://forum.wixstudio.com/t/wix-location-to-an-internal-anchor-dynamic-pages/35669/6 "2018-05-13T08:37:12Z")

</div>

Hi Stephen!

My bad for not explaining.  
I gave an example and not a snippet. The ID field has a field key just as any other field and the correct one needs to be used.

 ![](https://us1.discourse-cdn.com/wix/original/3X/5/f/5fab1fab10712c696d41b727a1ebbd6157416fa3.png)  
Hope it helps!  
Best of luck!

Doron. 🙂

---

<div class="post-metadata">

**Author:** ![stephenmccall](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/stephenmccall/32/1773_2.png) [@stephenmccall](https://forum.wixstudio.com/u/stephenmccall)\
**Post date:** [May 13, 2018, 9:07am UTC](https://forum.wixstudio.com/t/wix-location-to-an-internal-anchor-dynamic-pages/35669/7 "2018-05-13T09:07:44Z")

</div>

Hi Doron,

Must admit I feel like a bit of an idiot as I should’ve known better… anyway thank you for getting back to me.  
I was wondering though about how this affect the display of the URL?

Best wishes

Stephen

---

<div class="post-metadata">

**Author:** ![millwards322](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/millwards322/32/13622_2.png) [@millwards322](https://forum.wixstudio.com/u/millwards322)\
**Post date:** [October 15, 2019, 10:36pm UTC](https://forum.wixstudio.com/t/wix-location-to-an-internal-anchor-dynamic-pages/35669/8 "2019-10-15T22:36:11Z")

</div>

Ok im trying to do this on my site but it doesn’t work :S

---

<div class="post-metadata">

**Author:** ![stephenmccall](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/stephenmccall/32/1773_2.png) [@stephenmccall](https://forum.wixstudio.com/u/stephenmccall)\
**Post date:** [October 15, 2019, 10:46pm UTC](https://forum.wixstudio.com/t/wix-location-to-an-internal-anchor-dynamic-pages/35669/9 "2019-10-15T22:46:06Z")

</div>

Do you have some code that we could look at?

---

<div class="post-metadata">

**Author:** ![millwards322](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/millwards322/32/13622_2.png) [@millwards322](https://forum.wixstudio.com/u/millwards322)\
**Post date:** [October 15, 2019, 10:55pm UTC](https://forum.wixstudio.com/t/wix-location-to-an-internal-anchor-dynamic-pages/35669/10 "2019-10-15T22:55:45Z")

</div>

@stephenmccall Hi Stephen thanks for the fast reply and sure this is the complete page code im navigating away from

**import** wixLocation **from** ‘wix-location’;  
**import** wixData **from** ‘wix-data’;  
**import** wixUsers **from** ‘wix-users’;

export function vectorImage20\_click(event) {

**let** email = $w(“#companyEmail”).value;

```
         wixLocation.to(`mailto:${email}?subject=` +          
            encodeURIComponent("Job Enquiry")     
         );  
    } 

```

export function vectorImage19\_click(event) {  
**let** url = $w(“#websiteInfo”).value;  
wixLocation.to(`${url}`);  
}

export function vectorImage21\_click(event) {  
**let** mob = $w(“#mobile”).value;  
wixLocation.to(`tel:+${mob}`);  
}

export function iconButton1\_click(event) {  
**let** phone = $w(“#landline”).value;  
wixLocation.to(`tel:+${phone}`);  
}

export function reviews\_click(event,$w) {

wixLocation.to(`/Updatedmemberprofile/${`\_id`}?a=1`);

}

//and this is the page its navigating to’s partial code…

**import** wixData **from** ‘wix-data’;  
**import** wixWindow **from** ‘wix-window’;  
**import** { session } **from** ‘wix-storage’;  
**import** wixLocation **from** ‘wix-location’;  
**import** wixUsers **from** ‘wix-users’;  
**import** wixCrm **from** ‘wix-crm’;

$w.onReady( **function** () {

**let** query = wixLocation.query;  
**if** (query.a == 1){  
$w(“#anchor1”).scrollTo();  
}

Thanks

---

<div class="post-metadata">

**Author:** ![stephenmccall](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/stephenmccall/32/1773_2.png) [@stephenmccall](https://forum.wixstudio.com/u/stephenmccall)\
**Post date:** [October 15, 2019, 10:59pm UTC](https://forum.wixstudio.com/t/wix-location-to-an-internal-anchor-dynamic-pages/35669/11 "2019-10-15T22:59:23Z")

</div>

@millwards322 Try this

```javascript
 wixLocation.to(/Updatedmemberprofile/) + "#youranchorIDhere";  

```

Also if you highlight your code, right-click and click the box with the little arrow and line inside it will make the code easier to read in the grey box, like above 🙂

---

<div class="post-metadata">

**Author:** ![millwards322](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/millwards322/32/13622_2.png) [@millwards322](https://forum.wixstudio.com/u/millwards322)\
**Post date:** [October 15, 2019, 11:11pm UTC](https://forum.wixstudio.com/t/wix-location-to-an-internal-anchor-dynamic-pages/35669/12 "2019-10-15T23:11:34Z")

</div>

```javascript
mport wixLocation from 'wix-location'; 

import wixData from 'wix-data';
import wixUsers from 'wix-users'; 
     

export function reviews_click(event,$w) { wixLocation.to(`/Updatedmemberprofile/${`_id`}?a=1`); } 

```

```javascript
import wixData from 'wix-data';
import wixWindow from 'wix-window';
import { session } from 'wix-storage';
import wixLocation from 'wix-location';
import wixUsers from 'wix-users';
import wixCrm from 'wix-crm';

let title;

$w.onReady(function () {

 let query = wixLocation.query;
 if(query.a == 1){
           $w("#anchor1").scrollTo();
    }
    title = $w('#dynamicDataset').getCurrentItem();
    initReviews();
});

```

Hi thanks for pointing this out, and the problem is its not navigating to the correct site members id, i want a non logged in member to be able to navigate to a site members profile

thanks

---

<div class="post-metadata">

**Author:** ![millwards322](https://sea1.discourse-cdn.com/wix/user_avatar/forum.wixstudio.com/millwards322/32/13622_2.png) [@millwards322](https://forum.wixstudio.com/u/millwards322)\
**Post date:** [October 16, 2019, 11:22am UTC](https://forum.wixstudio.com/t/wix-location-to-an-internal-anchor-dynamic-pages/35669/13 "2019-10-16T11:22:59Z")

</div>

You any ideas @skmedia ? I’ve tried just about every field key name there is lol and I can’t still access my MembersProfile db to find out the correct field key name of the Updatedmembersprofile page, I’ve reported the issue but it’s been like it for days now :S seems strange the other db’s are working ok though, can you remember what the correct id is? Thanks
