0

I have some code that someone wants to put on their site. Here is the code i received from them:

<script language="JavaScript" src="http://dm4.contactatonce.com/scripts/PopIn.js" type="text/javascript"></script>
<script language="JavaScript" src="http://dm4.contactatonce.com/PopInGenerator.aspx?MerchantId=44542&ProviderId=3176&PlacementId=0" type="text/javascript">    </script>

<script language="JavaScript">
popIn();
</script>

The way this particular site is set up I cannot pick and choose which page to display it on - it has to go in the <head> of every page. The problem is that i want it to NOT show up on only one particular page. THe page name is /CreditApplication.aspx. I know i need to add an if statement to check the URL but i'm not quite sure how to accomplish that with this particular code as it uses external javascript files.

Any help would be great appreciated!

Thanks!

EDIT: Thanks for all the answers! Let me clarify one thing: the reason i need this is because the page the code is going on is a secured (https) page. These js scripts are not using secured links so in some browsers it gives you an error saying "some content on this page may not be secure" or whatever. I am trying to make sure these don't run on only this page. That's why i need the conditional statement on them. Hope that helps.

RyanPitts
  • 573
  • 4
  • 11
  • 27
  • Potentially examine the request object. Javascript might have this object but in .NET its something like Request.URL. – brumScouse Oct 28 '10 at 18:16
  • i don't necessarily need the code in .NET. Actually a Javascript snippet of code would be more helpful. – RyanPitts Oct 28 '10 at 18:19
  • Why do you say this can only go on the HEAD of every page? JavaScript doesn't always have to go in the HEAD element, you can just place it in the HTML of the specific page: /CreditApplication.aspx – Sandro Oct 28 '10 at 18:33
  • 1
    You should use ` – drudge Oct 28 '10 at 18:36

3 Answers3

4

How about


if (! /CreditApplication\.aspx$/.test(window.location.href) {
popIn();
}

Edit the regex as needed if the page can accept parameters.

mpdonadio
  • 2,851
  • 3
  • 29
  • 52
0

Try this:

<script>
window.location.pathname !== '/CreditApplication.aspx' && 
document.write(unescape('%3Cscript src="http%3A//dm4.contactatonce.com/PopInGenerator.aspx%3FMerchantId%3D44542%26ProviderId%3D3176%26PlacementId%3D0%22%20type%3D%22text/javascript')) &&
document.write(unescape('%3Cscript src="http%3A//dm4.contactatonce.com/scripts/PopIn.js"%3E%3C/script%3E'));
</script>
AutoSponge
  • 1,426
  • 10
  • 7
  • `document.write` is not such a good idea. http://stackoverflow.com/questions/802854/why-is-document-write-considered-a-bad-practice – Matt Ball Oct 28 '10 at 18:38
0

I'm not completely sure I'm following your question, but if I am here is how to get started:

if(window.location.href.indexOf("/CreditApplication.aspx") === -1) {
  popIn();
}
sworoc
  • 1,431
  • 12
  • 13