Check if a user visited a page? - javascript

I don't think this is possible, but perhaps someone knows of a way. I know Gleam.io is doing something similar, so maybe there is a way.
I have a button that if you click it, it opens somesite.com. The user clicks a button and I open this page with javascript. The problem is, after clicking the button, I want to know for sure the user opened the page. Maybe even go as far as making sure he scrolled to the bottom.
Is this in any way possible? Keeping mind that the target URL can vary.

You can user 'mixpanel.com' for track the user and also put a scroll event with particular width and add that user in database or use any platform like 'mixpanel' for track the user.

Related

Detecting a user leaving my website [duplicate]

I've searched for hours, but I couldn't find a solution for this.
window.onbeforeunload = warn;
This doesn't work:
function warn (e)
{
var destination = e.href;
alert(destination );
}
Okay, so to clear the things. If the user clicks on a link on the page itself, it is easy, because you can add an eventhandler to all of the links onclick event, but. I want to catch the address, what the user types into the url box of the browser.
Because it can't be done. The new location is private/sensitive information.
Nobody wants you to know which sites they visit when they leave your site.
If you just want to see what link destination, you can use :
document.activeElement.href
But getting the address line destination is not possible.
I've heard of solutions where they fire off an event if the mouse moves up to the address line (to warn the user that there are unfinished processes that have not been dealt with), but this sort of hack I would never do.
Kaze's answer is an interesting approach, but looking at the element focus when the page is navigated away from isn't really reliable. Partly because there is a delay between the link click and the navigation away from the page (during which time the user may move focus to some other element, but also because a link may be focused (eg. by keyboard control, or mousedown-without-click) without actually being used to navigate away from the page. So if you focused a link then closed the window, it'd think you were following the link.
Trapping onclick for every link on the page (plus onsubmit on every form) is slightly more reliable, but can still be fooled due to the delay. For example you click a link, but then before the new page starts loading hit the back button (or press Escape). Again, if you close the window it thinks you're following the link.
I want to catch the address, what the user types into the url box of the browser.
There is no way that will ever happen. It is an obvious privacy no-no.

Browser back button and javascript

It's possible to show some message on the page when you set mouse cursor on the browser back button? I don't want to use window.onbeforeunload, because it's irritating. I use ajax and I want to inform users that if they want to go back to the previous page on my web portal they should use a different button.
Is it possible to do it?
Thanks for your help
It is not possible to handle the mouse moving on the browser buttons, these are not part of the DOM that your scripts can handle.
There is an answer available here, which proposes a way of preventing users going back through the browser's back button.

javascript how to know the target page before redirect the whole page

Well, it should be easy.
Assume I have a page and there are multiple links and buttons on it.
Those links and buttons may links to anywhere in the internet.
Now, what I am trying to do is to check, after user clicking a link or button, to where the page is going to be redirected. If the target page is within the same domain of current page's domain, then allow the redirecting, otherwise stop it.
Is there anyway to do it? I mean I cannot retrieve the URL before the clicking, and there are a lot of buttons which I cannot write function for each of them. I need to single function which can monitor all the ongoing redirecting action.
I know there is a 'onbeforeunload' function which allow me to do the something before the current page is going to be unloaded. However, I don't know where can I find the target URL.
Is there anyone have idea about this?
Thanks in advance!
It can't be done using onbeforeunload. The new location is private/sensitive information. Who would want you to know which sites they visit when they leave your site.
The only way would be to try and hook everything on the page, links, buttons, etc and even then you really want to do that to your users? Invading their privacy is a sure way to make them very upset.

Prevent browser from snapping to previous scroll position when pushing back button

I need to prevent browser from snapping to previous scroll position when the user pushed a back button like this:
<a href="javascript:history.go(-1)"
onClick="javascript:history.go(-1)" title="< GO BACK"></a>
after pushing that button the browser will return to the previous scroll position on this page
i want to stop that behavior and just load the top of the page.
Hope someone know a proper solution.
-exemple-
open a page scroll down go to a new page and hit the back button the page will auto scroll down to the place you scrolled before!
I'm fairly certain the behavior you're describing is is best classified as one of those things considered to be a user preference. (One of those things that you're not meant to tamper with)
#mrtsherman came up with a hack/workaround for this, but unless it's seriously breaking your webapp's usability, I think you should let the browser behave as the user would normally expect it to behave (and scroll to the position they were in when they left the page). Be sure to upvote mrtsherman for his sweet nugget of js if you use it.
I have the same problem and I haven't find yet the correct solution,
but I can give you a very good workaround for this problem.
Just scroll to the top before load the next page.
When the user click back, the browser will scroll to the top.
Example:
First Page:Next
Second Page:Back
Note that href="page1.htm" loads only if user select open in new window/tab
Excuse my English. I hope this helps.
I found a better solution!
Put the following code on every page:
<script>
setTimeout('window.scrollTo(0, 0);', 1);
</script>

How can I get the destination URL for the onbeforeunload event?

I've searched for hours, but I couldn't find a solution for this.
window.onbeforeunload = warn;
This doesn't work:
function warn (e)
{
var destination = e.href;
alert(destination );
}
Okay, so to clear the things. If the user clicks on a link on the page itself, it is easy, because you can add an eventhandler to all of the links onclick event, but. I want to catch the address, what the user types into the url box of the browser.
Because it can't be done. The new location is private/sensitive information.
Nobody wants you to know which sites they visit when they leave your site.
If you just want to see what link destination, you can use :
document.activeElement.href
But getting the address line destination is not possible.
I've heard of solutions where they fire off an event if the mouse moves up to the address line (to warn the user that there are unfinished processes that have not been dealt with), but this sort of hack I would never do.
Kaze's answer is an interesting approach, but looking at the element focus when the page is navigated away from isn't really reliable. Partly because there is a delay between the link click and the navigation away from the page (during which time the user may move focus to some other element, but also because a link may be focused (eg. by keyboard control, or mousedown-without-click) without actually being used to navigate away from the page. So if you focused a link then closed the window, it'd think you were following the link.
Trapping onclick for every link on the page (plus onsubmit on every form) is slightly more reliable, but can still be fooled due to the delay. For example you click a link, but then before the new page starts loading hit the back button (or press Escape). Again, if you close the window it thinks you're following the link.
I want to catch the address, what the user types into the url box of the browser.
There is no way that will ever happen. It is an obvious privacy no-no.

Categories

Resources