Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Javascript > Using Javascript to rotate through web checkout shopping comparison surveys

Reply
Thread Tools

Using Javascript to rotate through web checkout shopping comparison surveys

 
 
sales@competitiveedgeproducts.com
Guest
Posts: n/a
 
      02-27-2006
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">
<!-- Reviews Code
var rand = Math.random();
if(rand < 0.25)

<!-- BEGIN: BizRate Survey Invitation HTML -->
<script language="JavaScript"
src="https://eval.bizrate.com/js/pos_*****.js"
type="text/javascript"></script>
<!-- END: BizRate Survey Invitation HTML -->

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>


Thanks in advance!
Shawn

 
Reply With Quote
 
 
 
 
web.dev
Guest
Posts: n/a
 
      02-27-2006

(E-Mail Removed) 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?


>From just skimming at the code, you'll be going through a lot of edits.

Let's see if we can do some incremental changes til we reach the goal
we want.

> <SCRIPT language="JavaScript">


The language attribute is deprecated, use the type attribute instead:

<script type = "text/javascript">

> <!-- Reviews Code


HTML comment delimiters are unnecessary. If you want to comment, why
not just use javascript comment delimiters:

//reviews code

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


Remove HTML comment delimiters.

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


Problem: You cannot have nested scripts.

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


Remove HTML comment delimiters

> <!-- 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>


Remove HTML comment delimiters and move the script tag outside.

> <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>


Problem: You are now mixing javascript code with HTML. HTML code is
separate from javascript.

> <!-- End PriceGrabber Code -->


Remove HTML comment delimiter.

> if(rand < 0.75)
>
> <iframe width="0" height="0"
> src="https://merchants.nextag.com/seller/review/popup.jsp?id=*******"></iframe>


Problem: Mixing HTML and javascript code again.

> <script language="JavaScript"
>
> src="https://www.shopping.com/xMerchantSurvey.js?pt=js&direct=1&mid=******">
>
> </script>


Problem: another nested script.

> // -->


Finally, remove the above as well. This will be our first step to
getting to your goal. After you have cleaned up the code above, post
the new changes and we can proceed from there.

 
Reply With Quote
 
 
 
 
RobG
Guest
Posts: n/a
 
      02-27-2006
http://www.velocityreviews.com/forums/(E-Mail Removed) 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
 
Reply With Quote
 
sales@competitiveedgeproducts.com
Guest
Posts: n/a
 
      02-28-2006
Thanks Rob,

I tried the array code, however it didn't do anything. It seems like
the randURL is just generating a number rather that representing the
string url value. Is there something else I need? The other problem is
that the bizrate url is to a javascript and when it is launched in the
browser as this "https://eval.bizrate.com/js/pos_*****.js" instead of
as a script like below - it displays a bunch of nasty code. I think
they did it as a javascript so that the popup blockers would not block
it erroneously.

<!-- BEGIN: BizRate Survey Invitation HTML -->
<script language="JavaScript"
src="https://eval.bizrate.com/js/pos_*****.js"
type="text/javascript"></script>
<!-- END: BizRate Survey Invitation HTML -->

Thanks,
Shawn

 
Reply With Quote
 
RobG
Guest
Posts: n/a
 
      03-01-2006
(E-Mail Removed) wrote:
> Thanks Rob,
>
> I tried the array code, however it didn't do anything. It seems like
> the randURL is just generating a number rather that representing the
> string url value. Is there something else I need?


Yes, code that works! Replace the following line:

var randURL = Math.floor(urlArray.length*Math.random());


with:

var randURL = urlArray[Math.floor(urlArray.length*Math.random())];


> The other problem is
> that the bizrate url is to a javascript and when it is launched in the
> browser as this "https://eval.bizrate.com/js/pos_*****.js" instead of
> as a script like below - it displays a bunch of nasty code. I think
> they did it as a javascript so that the popup blockers would not block
> it erroneously.


I don't want to have anything to do with testing the URLs. My intention
was to show how to put a random element into a page using document.write().

The values of the elements of the array should be strings that when
written to the document create valid HTML. I'll change the name to
htmlArray since that's what's in there.

For example, to write exactly what you had in your first post, declare
the array as:

// Initialise array
var htmlArray = [];

// BizRate element
htmlArray[0] = '<!-- BEGIN: BizRate Survey Invitation HTML -->'
+ '<script type="text/javascript" '
+ 'src="https://eval.bizrate.com/js/pos_*****.js"'
+ '><\/script>'
+ '<!-- END: BizRate Survey Invitation HTML -->';

// PriceGrabber element
htmlArray[1] = '<!-- PriceGrabber Merchant Evaluation Code -->'
+ '<script type="text/javascript">'
+ 'var popup_pos_x=200;'
+ 'var popup_pos_y=20;'
+ 'var popup_title_color="#000080";'
+ 'var popup_title_font_color="#FFFFFF";'
+ '<\/script>'
+ '<script type="text/javascript"'
+ 'src="https://www.pricegrabber.com/'
+ 'rating_merchrevpopjs.php?retid=****"'
+ '><\/script>'
+ '<!-- End PriceGrabber Code -->';


There seems little point in using script to write a no script element.
Add more as appropriate, then...

// Randomly select one to write to the page
var randHTML = htmlArray[Math.floor(htmlArray.length*Math.random())];

document.write(randHTML);


You will have a bunch of HTML in your page that may never get used -
maybe that's not a problem.


--
Rob
 
Reply With Quote
 
sales@competitiveedgeproducts.com
Guest
Posts: n/a
 
      03-02-2006
Thank you. It looks like the document.write command does the trick for
nested scripts.

 
Reply With Quote
 
sales@competitiveedgeproducts.com
Guest
Posts: n/a
 
      03-02-2006
Thank you Rob! I was able to get it to work with your awesome code.

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
How to rotate a DIV through CSS or Javascript Sura Javascript 3 08-14-2009 02:35 PM
managing releases of web applications: is svn checkout the best way? Ksenia Python 2 10-07-2008 09:23 AM
PIL rotate : Rotate By Shear / Paeth Rotation? IanJSparks Python 0 01-10-2008 04:50 PM
Rotate the graphics without rotate the text in SVG RC XML 1 08-03-2006 07:45 AM
Why does Visual Studio always checkout files when looking Web User Control in design mode? Eric Mamet ASP .Net 0 01-30-2004 10:38 AM



Advertisments