473,403 Members | 2,183 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,403 software developers and data experts.

Script only works in one URL

6
I am trying to write a scriupt to serve ad slot for each region. URL's are generated dynamically. OK, so I have the following code to display the ad (Google Ad Manager)

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript"> 
  2. if (location.href.substring(75,76) == "1")
  3. {
  4. GA_googleFillSlot("Button4");
  5. }
  6. </script>
The script works fine as long as the page is served from http://www.atlanticportal.com

The Problem is that the script wont work with any of the other URL's that I have such as Http://atlanticportal.com or http://www.atlanmticportal.ca

How can I fix this?
reply
Feb 24 '10 #1
9 1607
gits
5,390 Expert Mod 4TB
what should be really checked in your line 2?

kind regards
Feb 24 '10 #2
gdicks
6
I am trying to have change the ads based on the Region. For Example: If region = 1 show ad slot 6.

If you look at the following URL the ads show up at the left hand menu column. http://www.atlanticportal.com/Atlant...onName=Western
but they dont show up in the following url
http://www.atlanticportal.ca/Atlanti...onName=Western

The only difference in the url's is one is .com and the other is .ca
Feb 24 '10 #3
gits
5,390 Expert Mod 4TB
as you might see that is the problem ... your substring method relies on the position of the character you want to check ... so it doesn't match when anything is changed before ... like the domain name.

i would suggest to use a regExp ... like this:

Expand|Select|Wrap|Line Numbers
  1. if (/region=1/ig.test(location.href)) {
  2.     alert('match region 1');
  3. }
kind regards
Feb 25 '10 #4
gdicks
6
OK so I have the following code and it works for each URL, however, it seems rather cumbersome. Is there a way to simplify this by using a relative path perhaps?

Expand|Select|Wrap|Line Numbers
  1. <script type="text/javascript">
  2.     if (document.location.href.substr(74,75,76) == "1" || location.href == "http://www.atlanticportal.com/AtlanticPortal/en/WhereToStay.aspx?Region=1&Community=0&Category=1&ProvID=1&RegionName=Western" || location.href == 
  3.  
  4. "http://www.atlanticportal.ca/AtlanticPortal/en/WhereToStay.aspx?Region=1&Community=0&Category=1&ProvID=1&RegionName=Western" || location.href == 
  5.  
  6. "http://atlanticportal.ca/AtlanticPortal/en/WhereToStay.aspx?Region=1&Community=0&Category=1&ProvID=1&RegionName=Western" || location.href == 
  7.  
  8. "http://atlanticportal.com/AtlanticPortal/en/WhereToStay.aspx?Region=1&Community=0&Category=1&ProvID=1&RegionName=Western")
  9.         {   
  10.         GA_googleFillSlot("Button4");}
  11. </script>
Feb 25 '10 #5
gits
5,390 Expert Mod 4TB
huhh? ... why don't you use the regExp condition i showed you above? :) ...
Feb 25 '10 #6
gdicks
6
I tried it but it didnt work...
Feb 25 '10 #7
gits
5,390 Expert Mod 4TB
please show what you have tried ... the regExp should always match when region=1 is contained by the string that is tested ...
Feb 25 '10 #8
gdicks
6
First off, I have to say a big thank you for you taking the time to help me out! I really appreciate it. Good Karma for you!

I used the code as you posted it, but when I used your code, I got a pop up asking me to confirm that region =1. Once clicked to confirm, the page displayed properly.
Feb 25 '10 #9
gits
5,390 Expert Mod 4TB
remove the alert() ... i just showed it as an example ...
Feb 26 '10 #10

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

Similar topics

8
by: Sticks | last post by:
ok... im not quite sure how to describe my problem. i have a php script that runs through my entire php site and writes the resulting output to html files. this is necessary as the nature of the...
12
by: bhennon | last post by:
Hey all, I have a small php script that calls a random image at the following page. http://www.2006ymcanationals.com/random.php IT WORKS IF I go directly to the above link. I am trying to...
5
by: Tim Morrison | last post by:
Is there any easy way to create a change script as illustrated below for all tables within a database? Right now I would have to create a seperate script for each table. I would like to be able...
5
by: Yves-Alain NICOLLET | last post by:
How is it that when I include a script within a document it works and when I try to get it from my webserver it does not seem to work at all? I have documents on my webserver that contain a...
5
by: zaw | last post by:
Hi I am working on implementing this script to shopping cart. Basically, it copies fill the shipping address from billing automatically. I believe one or more syntax is not netscape compatible....
23
by: Loony | last post by:
I have got a code like this in HTML section in ASP file which includes javascript file! The script works under MS IE but doesn't with Firefox! Can anybody tell me what is wrong? <HTML>...
9
by: Jerim79 | last post by:
I am no PHP programmer. At my current job I made it known that I was no PHP programmer during the interview. Still they have given me a script to write with the understanding that it will take me a...
8
by: Milsnips | last post by:
hi there, i'm currently using the following line: <script language="javascript" type="text/javascript" src="../scripts/timer.js"></script> but i want to do the following, as the script...
9
by: 8anos | last post by:
Hello, I am new at the community and newbie at programming :) As you may know rapidshare provides a perl script for linux, to upload files at their servers. You can find the original scripts at...
1
by: rfr | last post by:
Apparently the Transitional Doctype kills this script because the script does not make proper use of units like "px". It works well without a doctype statement. But once someone adds a...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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...
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
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
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
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
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.