homepage Welcome to WebmasterWorld Guest from 50.19.33.5
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Javascript history object
history.previous question
delvsie




msg:1493138
 10:28 pm on Jan 30, 2003 (gmt 0)

Hi all,

I am not very good when it comes to writing Javascript, however, I'm currently building a site and I have a problem. I have a page that can be accessed by two different pages (only images on the page) and I need to be able to identify which page the user has come from. This is so that I can then display an image specific to the page that they have come from in, conjuction with a generic image that will appear in both cases. I do not want to have two separate pages as this will result in maintenance overheads.

I thought about using the history.previous method but don't seem to be able to get the url of the page so that I can then identify which image to display.

In English, what I thought I could do was:

Use the onLoad event to capture the history.previous value, then use an if statement to determine which image to display. The images would be in <div> tags both with a 'style=display:none' statement so that they would be hidden.

Can anyone help me with the code that I need to write. Or advise me of a better way to do what I require?

Thanks in advance for any help.

 

DrDoc




msg:1493139
 10:39 pm on Jan 30, 2003 (gmt 0)

delvsie,

There are several ways to do it. One, you can check the document.referrer value .. which should contain the URL for the previous page.

But, you can also use a query string when accessing the page. Instead of linking to blah.html you can link to blah.html?thispage.html where thispage.html is the name of the refering page.

Then you could just use the following JavaScript on the blah.html page.

<script type="text/javascript">
a=location.search.substring(1);
</script>

The a variable will now contain the name of the previous page, and you can check it to hide/unhide images, put in backlinks .. etc

Hope that little info helps :)

tedster




msg:1493140
 10:44 pm on Jan 30, 2003 (gmt 0)

You also might pass a variable in a query string at the end of the URL in the anchor on each tag, as simple as a "1" or a "2". So the anchor would be written <a href="newpage.html?im=1">link</a>

Then your script on the target page just extracts the passed variable and writes the appropriate image into the div.

I think this approach would be more dependable than assuming the window history will always give you the object you want. For instance, I often open links in a a new window.

delvsie




msg:1493141
 10:52 pm on Jan 30, 2003 (gmt 0)

DrDoc and tedster...

Thanks for the speedy reply. I will take on board what you have said.

Thanks again. :)

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved