views:

55

answers:

4

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&amp;ProviderId=3176&amp;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.

+1  A: 

How about


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

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

MPD
A: 

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
`document.write` is not such a good idea. http://stackoverflow.com/questions/802854/why-is-document-write-considered-a-bad-practice
Matt Ball
For script tags, it's the best way: http://html5boilerplate.com/
AutoSponge
A: 

Does the URL that shows up in the browser end with /CreditApplication.aspx? If so - and if I understand correctly what you're trying to not do on this page, then this should work:

<script>
    if (!/\/CreditApplication\.aspx$/.test(window.location.pathname))
    {
        popIn();
    }
</script>
Matt Ball
A: 

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