开发者

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/开发者_StackOverflowscripts/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.


How about


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

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


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>


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

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜