RyanPitts
RyanPitts

Reputation: 601

Check URL for page name

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.

Upvotes: 0

Views: 2875

Answers (3)

sworoc
sworoc

Reputation: 1461

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();
}

Upvotes: 0

AutoSponge
AutoSponge

Reputation: 1454

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>

Upvotes: 0

mpdonadio
mpdonadio

Reputation: 2941

How about


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

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

Upvotes: 4

Related Questions