Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. Web Development
  3. JavaScript
  4. Reading Address Before Browser Loads It?

Reading Address Before Browser Loads It?

Scheduled Pinned Locked Moved JavaScript
javascriptphpdatabasetoolsquestion
6 Posts 4 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    weinerschizel
    wrote on last edited by
    #1

    I'm writing a simple piece of code to display a popup when somebody leaves my wordpress blog. It will simply ask if they wanted to register for my next open house before they leave the website. Here's what I have...

    <script language="JavaScript">
    window.onbeforeunload = confirmExit;
    function confirmExit()
    {
    return "Have you registered for my open house tour?";
    }
    </script>

    That displays everytime a page is unloaded though... I want to simply check what the next page is and if it doesn't contain my domain then trigger the popup. I found this code but it won't work because it shows the previous pages address when I need to see the next page to loads address.

    var s = window.location.href;
    var s = window.
    return s;

    Does anybody know how I can grab the next page that will be loaded from the browser? Thanks!

    L 0 2 Replies Last reply
    0
    • W weinerschizel

      I'm writing a simple piece of code to display a popup when somebody leaves my wordpress blog. It will simply ask if they wanted to register for my next open house before they leave the website. Here's what I have...

      <script language="JavaScript">
      window.onbeforeunload = confirmExit;
      function confirmExit()
      {
      return "Have you registered for my open house tour?";
      }
      </script>

      That displays everytime a page is unloaded though... I want to simply check what the next page is and if it doesn't contain my domain then trigger the popup. I found this code but it won't work because it shows the previous pages address when I need to see the next page to loads address.

      var s = window.location.href;
      var s = window.
      return s;

      Does anybody know how I can grab the next page that will be loaded from the browser? Thanks!

      L Offline
      L Offline
      Luc Pattyn
      wrote on last edited by
      #2

      Sorry, but I can only say I hope you will not get a solution ever, as my next page is none of your business! Besides, what if the visitor closes his browser or his browser tab? When he does, there isn't a next page. A better approach could be this: have each of your pages ask the question under some conditions, such as: 1. ask it only once 2. ask it only when the visitor has been on your site for more than 2 minutes 3. ask it only when the visitor has been on the same page for more than 20 seconds :)

      Luc Pattyn [My Articles] Nil Volentibus Arduum

      B W 2 Replies Last reply
      0
      • L Luc Pattyn

        Sorry, but I can only say I hope you will not get a solution ever, as my next page is none of your business! Besides, what if the visitor closes his browser or his browser tab? When he does, there isn't a next page. A better approach could be this: have each of your pages ask the question under some conditions, such as: 1. ask it only once 2. ask it only when the visitor has been on your site for more than 2 minutes 3. ask it only when the visitor has been on the same page for more than 20 seconds :)

        Luc Pattyn [My Articles] Nil Volentibus Arduum

        B Offline
        B Offline
        BobJanova
        wrote on last edited by
        #3

        You're probably right, it's probably not available to script for security/privacy reasons.

        1 Reply Last reply
        0
        • L Luc Pattyn

          Sorry, but I can only say I hope you will not get a solution ever, as my next page is none of your business! Besides, what if the visitor closes his browser or his browser tab? When he does, there isn't a next page. A better approach could be this: have each of your pages ask the question under some conditions, such as: 1. ask it only once 2. ask it only when the visitor has been on your site for more than 2 minutes 3. ask it only when the visitor has been on the same page for more than 20 seconds :)

          Luc Pattyn [My Articles] Nil Volentibus Arduum

          W Offline
          W Offline
          weinerschizel
          wrote on last edited by
          #4

          I'm fairly novice when it comes to Javascript. What variables store these conditions / time on page? I understand I'll probably write a cookie so it only alerts the visitor once. I do like the idea of prompting them after they've been on the site for a certain period of time. fyi. My goal is simple. People may have not noticed the information they need so I want to indicate such. I just want to provide a little alert box or something to redirect them if they choose.

          L 1 Reply Last reply
          0
          • W weinerschizel

            I'm fairly novice when it comes to Javascript. What variables store these conditions / time on page? I understand I'll probably write a cookie so it only alerts the visitor once. I do like the idea of prompting them after they've been on the site for a certain period of time. fyi. My goal is simple. People may have not noticed the information they need so I want to indicate such. I just want to provide a little alert box or something to redirect them if they choose.

            L Offline
            L Offline
            Luc Pattyn
            wrote on last edited by
            #5

            weinerschizel wrote:

            What variables store these conditions / time on page?

            None. You have to code that yourself. You could start a timer when the page loads, show your message when the timer expires, or pass on the time when you leave to the next page of your site, so it can load its timer with the value carried over (through cookie or URL). And I haven't actually done any of this, as I don't like such reminders at all... :)

            Luc Pattyn [My Articles] Nil Volentibus Arduum

            1 Reply Last reply
            0
            • W weinerschizel

              I'm writing a simple piece of code to display a popup when somebody leaves my wordpress blog. It will simply ask if they wanted to register for my next open house before they leave the website. Here's what I have...

              <script language="JavaScript">
              window.onbeforeunload = confirmExit;
              function confirmExit()
              {
              return "Have you registered for my open house tour?";
              }
              </script>

              That displays everytime a page is unloaded though... I want to simply check what the next page is and if it doesn't contain my domain then trigger the popup. I found this code but it won't work because it shows the previous pages address when I need to see the next page to loads address.

              var s = window.location.href;
              var s = window.
              return s;

              Does anybody know how I can grab the next page that will be loaded from the browser? Thanks!

              0 Offline
              0 Offline
              0bx
              wrote on last edited by
              #6

              FYI, I may have some bad news: onload and onbeforeunload events aren't supported by Chrome, so it would be unwise to use it imo.

              Giraffes are not real.

              1 Reply Last reply
              0
              Reply
              • Reply as topic
              Log in to reply
              • Oldest to Newest
              • Newest to Oldest
              • Most Votes


              • Login

              • Don't have an account? Register

              • Login or register to search.
              • First post
                Last post
              0
              • Categories
              • Recent
              • Tags
              • Popular
              • World
              • Users
              • Groups