dcsimg
www.webdeveloper.com
Results 1 to 9 of 9

Thread: Conditional operation on return to index.htm

  1. #1
    Join Date
    Feb 2007
    Posts
    95

    Conditional operation on return to index.htm

    When you open my site's "index" page a javascript is run that displays an alert. I want the alert to be a one-time event; I do not want this alert to be displayed if you are returning to the index from one of my other pages.

    I assume what I have to do is add a conditional statement to the javascript that displays the alert. But I can't figure out how to return a variable from the other page that can be used in a script. I only know how to use returned data within a script.

    I have a work-around. In it I have the "index" page and an "index_return" page. They are idential except that the "index_return" does not have the alert in it. All links from other pages go to "index_return" thus avoiding the recurring alert. But this requires maintaining two index pages. That's a pain and it is easy to forget to update both pages.

    There's got to be a better way. Can anyone help me?

    Cheers.

    Marcus

  2. #2
    Join Date
    Feb 2007
    Posts
    20
    The easiest solution would be to just make a copy of your index that doesn't have the javascript and link to that.

    You could even use a simple SSI line to drop in the index page data so that everything is precached (exactly as it would be the first time the other index was loaded).
    Last edited by Ashenwraith; 02-17-2007 at 06:42 PM.

  3. #3
    Join Date
    Jan 2005
    Posts
    3,067
    Quote Originally Posted by Ashenwraith
    The easiest solution would be to just make a copy of your index that doesn't have the javascript and link to that.

    You could even use a simple SSI line to drop in the index page data so that everything is precached (exactly as it would be the first time the other index was loaded).
    Actually, the best way is to use server-side sessions, or if you do not want to do it server-side, then simply use cookies.

  4. #4
    Join Date
    Feb 2007
    Posts
    20
    Quote Originally Posted by konithomimo
    Actually, the best way is to use server-side sessions, or if you do not want to do it server-side, then simply use cookies.
    Cookies is over complicating things since he doesn't need to save settings after the session and he would need to write excess code to read and write cookies.

  5. #5
    Join Date
    Jan 2005
    Posts
    3,067
    Quote Originally Posted by Ashenwraith
    Cookies is over complicating things since he doesn't need to save settings after the session and he would need to write excess code to read and write cookies.
    1. If you dont set an expiration for the cookie then it expires when the session is over.
    2. Reading and writing cookies does not take a whole lot of coding. It is only a few lines.
    3. The best way is still server-side, whether you choose to use sessions or not. The reason being that instead of creating two index pages as you suggest, you can just use includes to include the code that does not contain the alert, and then have a conditional that says whether or not to include the alert code. That way you only have one page, and thus only have to maintain one page.

  6. #6
    Join Date
    Feb 2007
    Posts
    20
    Quote Originally Posted by mlibkind
    When you open my site's "index" page a javascript is run that displays an alert. I want the alert to be a one-time event; I do not want this alert to be displayed if you are returning to the index from one of my other pages.

    I assume what I have to do is add a conditional statement to the javascript that displays the alert. But I can't figure out how to return a variable from the other page that can be used in a script. I only know how to use returned data within a script.

    I have a work-around. In it I have the "index" page and an "index_return" page. They are idential except that the "index_return" does not have the alert in it. All links from other pages go to "index_return" thus avoiding the recurring alert. But this requires maintaining two index pages. That's a pain and it is easy to forget to update both pages.

    There's got to be a better way. Can anyone help me?

    Cheers.

    Marcus
    SSI is for Server-Side Instructions

    See this link for more info:
    http://72.14.253.104/search?q=cache:...lnk&cd=1&gl=us

    All you need to do is create an .shtml file without the html, but with the javascript and use the code <!--#include file="myfile.html"--> for your html

    Then use this shtml file as the original index file and link directly to the html file for your other buttons.

    You won't be able to see the difference in your shtml file until after you have uploaded all of these files to your server.
    Last edited by Ashenwraith; 02-17-2007 at 11:54 PM.

  7. #7
    Join Date
    Feb 2007
    Posts
    20
    Quote Originally Posted by konithomimo
    3. The best way is still server-side, whether you choose to use sessions or not. The reason being that instead of creating two index pages as you suggest, you can just use includes to include the code that does not contain the alert, and then have a conditional that says whether or not to include the alert code. That way you only have one page, and thus only have to maintain one page.
    I already mentioned this in my first post.

    That's what SSI means.

  8. #8
    Join Date
    Jan 2005
    Posts
    3,067
    I know what SSI is, and how to use it, and it does not stand for Server-Side Instructions. It stands for Server-Side Includes, although some people like to refer to them as Server-Side Instructions, because they are not the same as includes from server-side languages such as PHP/ASP, although they are quite similiar. Many servers do not have SSI enabled, so they will not always work. And yes, some servers do not have server-side languages such as PHP/ASP installed, but the majority of them do, and I have come across quite a few servers that do not have SSI enabled. That being said, either way the OP has to determine whether or not to show the alert. One way or another you have to store data to determine if the alert has already been shown. You have to store it in a cookie, send it to every page via the querystring, store it in a server-side variable or a DB, or use sessions. You could also use the referrer, but some people have their security settings to not show that data, so it will not always work, just as using cookies or JS will not always work, since people can have them disabled. That is why, as I said before, the best solution is to use a server-side include.

  9. #9
    Join Date
    Feb 2007
    Posts
    20
    Quote Originally Posted by konithomimo
    I know what SSI is, and how to use it, and it does not stand for Server-Side Instructions. It stands for Server-Side Includes, although some people like to refer to them as Server-Side Instructions, because they are not the same as includes from server-side languages such as PHP/ASP, although they are quite similiar. Many servers do not have SSI enabled, so they will not always work. And yes, some servers do not have server-side languages such as PHP/ASP installed, but the majority of them do, and I have come across quite a few servers that do not have SSI enabled. That being said, either way the OP has to determine whether or not to show the alert. One way or another you have to store data to determine if the alert has already been shown. You have to store it in a cookie, send it to every page via the querystring, store it in a server-side variable or a DB, or use sessions. You could also use the referrer, but some people have their security settings to not show that data, so it will not always work, just as using cookies or JS will not always work, since people can have them disabled. That is why, as I said before, the best solution is to use a server-side include.
    What's the point of this long post? I mentioned using SSI in my first post - SSI is SSI - who cares if you use the I for instructions or includes?

    If you're trying to prove you're some kind of 'web-guru' or whatever, you can do that a lot better by coming over to my thread on converting javascript functions into objects (and do it without ranting about how all functions are really objects):

    http://www.webdeveloper.com/forum/sh...d.php?t=138786

    I've been waiting all day for you supposed experts to show up.
    Last edited by Ashenwraith; 02-18-2007 at 03:57 AM.

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
HTML5 Development Center



Recent Articles