473,388 Members | 1,408 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,388 software developers and data experts.

Dynamically change an image based on document.URL

Hello,


The objective of this script is to show visitors who found my site by clicking on one of our Google Adwords a specific telephone number (in graphic form) for the sake of tracking.


Here is the code I have been working on. My issue lies within the document.URL area of the script. I tried this code without declaring the source variable, but the script would redirect me to the document.URL declaration.


After running this code on a test page, it now displays the first image in the series, but should be showing the second image as the page I am viewing it on does not have the URL tied to it.






<script language = “javascript” type=”text/javascript”>
Expand|Select|Wrap|Line Numbers
  1.  
  2.  
  3. function adWords()
  4.  
  5.  
  6.  
  7. {
  8.  
  9.  
  10.  
  11. source=document.URL     <!-- If I eliminate this declaration and just use document.URL in the IF statement, the page gets redirected to that URL
  12.  
  13.  
  14.  
  15. if(source="http://www.appletreeanswers.com/index.html") { 
  16.  
  17.  
  18.  
  19. document.write("<IMG SRC='/normalimage.jpg'>")
  20.  
  21.  
  22.  
  23. }else{
  24.  
  25.  
  26.  
  27. document.write("<IMG SRC='/adwordimage.jpg'>")
  28.  
  29.  
  30.  
  31.  }
  32.  
  33.  
  34.  
  35. }
  36.  
  37.  
  38.  
  39.  
-->

</script>





<script language="javascript" type="text/javascript">



adWords();



</script>


Thanks!
Mar 28 '08 #1
3 3864
poe
32
The reason the page gets redirected is because your if statement is making an assignment instead of a comparison.

What you have: blah = blah2

What you need: blah == blah2

With what you have, as soon as you assign document.URL to something, the page location changes.
Mar 29 '08 #2
The reason the page gets redirected is because your if statement is making an assignment instead of a comparison.

What you have: blah = blah2

What you need: blah == blah2

With what you have, as soon as you assign document.URL to something, the page location changes.
Thanks, I am very new at JS, so I appreciate you taking the time to answer a simple question.

Chris
Mar 30 '08 #3
acoder
16,027 Expert Mod 8TB
Just a note: document.URL is read-only or, at least, should be. IE lets you set it.

For cross-browser functionality, if you ever need to change the URL, use location.href.
Apr 1 '08 #4

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

Similar topics

10
by: TheKeith | last post by:
I don't know much about javascript, so take it easy on me. Is there a way to dynamically change a CSS layers dimensions on the fly. Here is what I'm doing. I have a bunch of thumbnails that when...
2
by: Irvin Amoraal | last post by:
I am new to javascript coding. I am using some javascript code to change an image on an html page. I would like the user to click on the image to bring them to another page. I need to change an...
1
by: C A Upsdell | last post by:
I have a site where I am setting a style dynamically, using the JS statement: obj.style.backgroundImage = 'url(img/bak_page.jpg)'; where 'obj' is either document.getElementById(id), or...
9
by: pablo | last post by:
Dear NGers, I would like to change the alt-text with the changing of the image during a mouseover action. Can document.images.altView be changed dynamically? TIA, pablo
6
by: SPG | last post by:
Hi, I wrote a little bit of script that loads an image from a thumbnail when the thumbnail is clicked. It is not very clever, and I have found it only works in IE.. could someone have a look...
9
by: Robby Bankston | last post by:
I'm working on some code and am running into brick walls. I'm trying to write out Javascript with Javascript and I've read the clj Meta FAQ and didn't see the answer, read many similar posts (with...
3
by: SGA Smele | last post by:
Hello, Now I think that there is a simple answer to my problem, but I don't know what it is and I can't work out what I should be searching for on the internet to read up some more about it. ...
5
by: Jerry Camel | last post by:
I am interacting with an OCX on the client side. In the Onload event of the page, I am checking a property of the OCX: Is the port open or closed. If the port is open, I want a certain image to...
18
by: sandeepdesai | last post by:
Hi.. i am new to javascripts, i am using a addRow scipt to add rows to a table dynamically. one of the cells(say cell2) in a Nth row needs to be hyperlinked to another script. for example: ...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
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
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
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...

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.