473,398 Members | 2,389 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,398 software developers and data experts.

Display Image Based on Referred URL

I found the below script that will display an image based on certain date. I would like to add an additional function that will display the images when it is referred by a certain URL. IE. if users comes from yahoo.com they will see the special holiday graphic and if users comes from google.com they will see the default image.

Expand|Select|Wrap|Line Numbers
  1. <html>
  2. <head>
  3. <title>holiday image demo</title>
  4. <script type="text/javascript">
  5.  
  6. var holiday = [
  7. [ "1015", "1101", "halloween.jpg" ],
  8. [ "1210", "1226", "christmas.jpg" ],
  9. [ "1227", "1231", "newyear.jpg" ],
  10. [ "0101", "0102", "newyear.jpg" ]
  11. ];
  12.  
  13. function disable(){return false}
  14.  
  15. function setImgByDate(imgRef,dateList) {
  16. imgRef.onload = disable;
  17. var today = new Date();
  18. var month = 1+today.getMonth();
  19. if (month<10) month = "0"+month;
  20. var date = today.getDate();
  21. if (date<10) date = "0"+date;
  22. var MMDD = ""+month+date;
  23. for (var i=0; i<dateList.length; i++) {
  24. if (MMDD>=dateList[i][0] && MMDD<=dateList[i][1]) {
  25. imgRef.src = dateList[i][2];
  26. return;
  27. }
  28. }
  29. }
  30. </script>
  31. </head>
  32. <body>
  33. <img src="default.jpg"
  34. onload="setImgByDate(this,holiday)">
  35. </body>
  36. </html>
How can this be accomplished? Please assist.
Aug 8 '07 #1
4 3532
pbmods
5,821 Expert 4TB
Heya, abstractj. Welcome to TSDN!

Check out document.referrer.
Aug 9 '07 #2
So I tried testing the following and the script did not work. There were no error displayed... I'm not sure what I did wrong. I just want to display "Thanks for visiting this site" if the referrer URL comes from http://www.mysite.com/referrer.html
Expand|Select|Wrap|Line Numbers
  1. <script language="Javascript">
  2. <!-- 
  3.  
  4. if (document.referrer="http://www.mysite.com/referrer.html")
  5.   document.write('Thanks for visiting this site');
  6.  
  7. //-->
  8. </script>
Aug 9 '07 #3
pbmods
5,821 Expert 4TB
Heya, Abstract.

Please use CODE tags when posting source code. See the REPLY GUIDELINES on the right side of the page next time you post.

Perhaps you meant to use '==' instead of '='.
Aug 9 '07 #4
Okay, reading more on the subject and googling around I was able to find a code and hack it where it fits my need.

Where the indexOf will display the "you're from mysite.com" message if the referrer is coming from any page that is on mysite.com.

Thanks for the direction PBmods.
Expand|Select|Wrap|Line Numbers
  1. <SCRIPT LANGUAGE="JavaScript">
  2. if(document.referrer.length > 0 && document.referrer.indexOf("http://www.mysite.com") != -1){
  3.     document.write("you're from mysite.com")
  4. } else {
  5.     document.write("you're not from mysite.com")
  6. }
  7. </SCRIPT>
  8.  
Aug 9 '07 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

23
by: Erik Schulp | last post by:
Hi all, I am using a background image via a stylsheet. I've used this code: background-image:url("/images/tile.gif"); (which I think is correct) The image doesn't show up however, the path,...
2
by: e n | c k m a | last post by:
Anyone know how to keep the list-style-image visible when using display: inline for a horizontal list? Also, how to possibly have the text a little higher than the list-style-image? I've...
2
by: William Starr Moake | last post by:
For an IE-based offline WYSIWYG editor I'm developing, I have added javascript to insert images as table backgrounds and to set page background color. But I can't get any script to work for setting...
5
by: Peter Lapic | last post by:
I have to create a image web service that when it receives an imageid parameter it will return a gif image from a file that has been stored on the server. The client will be an asp.net web page...
3
by: c676228 | last post by:
Hi everyone, I have a piece of code in sales.aspx.vb like this: Protected WithEvents Message As System.Web.UI.WebControls.Label Try ... ChartImage.ImageUrl = "ChartGenerator.aspx?" + DataStr +...
3
by: Dave | last post by:
I have an ASP 3.0 website on which the images are displaying intermittently. In other words, when I request a page, the image is blank. There is no missing image place marker (rectangle with a...
3
by: Safalra (Stephen Morley) | last post by:
(Note: I'm not trying to do anything stupid based on the user's screen size - I'm just curious.) At work today I was looking at the visitor statistics for a client website, and noticed that...
2
by: smorrison64 | last post by:
I have a form that is coded to open a File Dialog boc to pick a picture to display on that particular item on a subform. My form is not based on query, but rather two separate tables (one primary,...
3
by: =?Utf-8?B?QmlsbHkgWmhhbmc=?= | last post by:
I have a asp.net app, in the page there is a scan activex which could scan and save a jpg file in client harddisk. How could we access and display this jpg file on the fly using js in the client...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.