Re: Using Javascript to rotate through web checkout shopping comparison surveys
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.javascript archive

Re: Using Javascript to rotate through web checkout shopping comparison surveys

From: RobG <rgqld@iinet.net.au>
Date: Tue Feb 28 2006 - 00:30:32 CET

sales@competitiveedgeproducts.com wrote:
> Hello,
>
> I am trying to get my website checkout page to rotate / take turns
> displaying shopping comparison engine surveys rather than display them
> all 4 at the same time, thus overwhelming & annoying the customer.
>
> I tried to put together some code to rotate through a Bizrate,
> PriceGrabber, Shopping.com and Nextag survey, I have taken the survey
> code the shopping comparison engines gave and tried to put it in a
> random number script to make them rotate. I have replaced our account
> numbers with asterisks below. Being new to javascript, I obviously
> have some major syntax errors or something. Would anyone be so kind
> and friendly as to show me what I need to change on this code to get it
> to work?
>
> <SCRIPT language="JavaScript">

The language attribute is deprecated, type is required

   <script type="text/javascript">

> <!-- Reviews Code

Do not use HTML style comment delimiters inside script elements, ever.
They server no useful purpose and are potentially harmful. Most
browsers will tolerate them before any real script is encountered, but
placed anywhere else in the script they will almost certainly cause
problems...

> var rand = Math.random();
> if(rand < 0.25)
>
> <!-- BEGIN: BizRate Survey Invitation HTML -->

Like here.

> <script language="JavaScript"
> src="https://eval.bizrate.com/js/pos_*****.js"
> type="text/javascript"></script>

You can't nest script elements...

> <!-- END: BizRate Survey Invitation HTML -->

Or put HTML style comments inside scripts...

>
> else
>
> if(rand < 0.5)
>
> <!-- PriceGrabber Merchant Evaluation Code --> <script
> language="javascript" type="text/javascript"><!-- popup_pos_x=200;
> popup_pos_y=20; popup_title_color = "#000080"; popup_title_font_color =
> "#FFFFFF"; //--> </script> <script language="javascript"
> src="https://www.pricegrabber.com/rating_merchrevpopjs.php?retid=****"
> type="text/javascript"></script>
> <NOSCRIPT>
> <A
> href="https://www.pricegrabber.com/rating_merchrevpop.php?retid=****"
> target=_blank>
> <img src="https://images.pricegrabber.com/images/rating_merchpopup.gif"
>
> border="0" width="480" height="166" alt="Merchant
> Evaluation"></A></NOSCRIPT>
> <!-- End PriceGrabber Code -->
>
> else
>
> if(rand < 0.75)
>
> <iframe width="0" height="0"
> src="https://merchants.nextag.com/seller/review/popup.jsp?id=*******"></iframe>
>
> else
>
> <script language="JavaScript"
>
> src="https://www.shopping.com/xMerchantSurvey.js?pt=js&direct=1&mid=******">
>
> </script>
> // -->
> </SCRIPT>

It seems that you want to randomly insert a script element into the
page. I'd suggest Using an array to store the script element URLs,
generate a random number within the range of the length of the array and
use that to randomise the URL.

e.g.

<script type="text/javascript">

   // Put URLs in here
   var urlArray = [
      'https://eval.bizrate.com/...',
      'https://www.pricegrabber.com/...',
      'https://merchants.nextag.com/...'
      ];

   // Now randomly select one to use in the script element
   // added to the page
   var randURL = Math.floor(urlArray.length*Math.random());

   document.write('<script type="text/javascript" src="'
                 + randURL + '"><\/script>');
</script>

Now to add more comparison sites, just add their URL to the array. The
script element added by the document.write is actually added immediately
after the above script element, it is not nested inside it.

-- 
Rob
Received on Mon May 1 03:40:17 2006