# Utilizing document.referrer with Knack? JavaScript

**URL:** https://forums.knack.com/t/utilizing-document-referrer-with-knack-javascript/6968
**Category:** Ask Developers
**Created:** [September 4, 2018, 6:26pm UTC](https://forums.knack.com/t/utilizing-document-referrer-with-knack-javascript/6968 "2018-09-04T18:26:23Z")
**Posts on this page:** 3
**Page:** 1

<div class="post-metadata">

### Author: ![Bharvey38896](https://avatars.discourse-cdn.com/v4/letter/b/977dab/32.png) [@Bharvey38896](https://forums.knack.com/u/Bharvey38896)
#### Post date: [September 4, 2018, 6:26pm UTC](https://forums.knack.com/t/utilizing-document-referrer-with-knack-javascript/6968/1 "2018-09-04T18:26:23Z")

</div>

I'm trying to read the referrer URL in order to redirect the user back to the details page. There might be a simpler way to do this, but basically I'm trying to read the incoming URL and redirect the user back to the project page once the print function is complete.

The problem I'm running into is the string that document.referrer returns. It does not look like the actual URL, but looks like this:

```
https://app.knack.com/appname?state=p%3Dgoogle%26s%3Dhome%26h%3Dhome&code=4/UADRJSVK5EPV9c5tX5pJMI_99b3i8jhLjuu8-eG_TxN6fpRzDdLy6mmwqFKIpKIs8uNl1BvOngvvs2pyVcCjxSE
```

And my script looks like this:

```
$(document).on('knack-scene-render.scene_96', function(event, scene) {
var referingPage = document.referrer;
setTimeout(function() {
window.print()
}, 900);
if (referingPage.indexOf("project-details") > -1) {
setTimeout(function() {
window.history.back()
}, 1000);
}

if (referingPage.indexOf("print-custom") > -1) {
setTimeout(function() {
window.history.go(-2);
}, 1000);
}
});
```

---

<div class="post-metadata">

### Author: ![Bharvey38896](https://avatars.discourse-cdn.com/v4/letter/b/977dab/32.png) [@Bharvey38896](https://forums.knack.com/u/Bharvey38896)
#### Post date: [September 5, 2018, 6:27pm UTC](https://forums.knack.com/t/utilizing-document-referrer-with-knack-javascript/6968/2 "2018-09-05T18:27:06Z")

</div>

I could do that Brad, but I sometimes need to go back two pages depending on how the user is getting to the print page view. For now, I'm kind of doing that with the a redirect back to the details page. It works, but starts adding pages to the breadcrumb.

```
var backURL = document.querySelector('#view_446 .kn-link-page').href;
setTimeout(function() {
window.print()
}, 900);
setTimeout(function() {
window.location.href = backURL;
}, 1200);
```

---

<div class="post-metadata">

### Author: ![BradStevens](https://sea2.discourse-cdn.com/flex020/user_avatar/forums.knack.com/bradstevens/32/140_2.png) [@BradStevens](https://forums.knack.com/u/BradStevens)
#### Post date: [September 4, 2018, 8:19pm UTC](https://forums.knack.com/t/utilizing-document-referrer-with-knack-javascript/6968/3 "2018-09-04T20:19:09Z")

</div>

Could you trigger the back link after the window.print instead?

```
$('.kn-view.kn-back-link').click();
```
