2

I'm using the window location and the DIV ID of IncludeCMSContent1, IncludeCMSContent2, IncludeCMSContent3 on a single page application. When those conditions are met the external content is injected at the ID.

However, I'm finding that only 1 of the 3 variables is firing, the first one actually, because if IncludeCMSContent3 is present on the page, this ID won't fire because IncludeCMSContent1 is taking precedence.

How can I solve for this? The page is always the same, so the value is always the same, but the ID of IncludeCMSContent1/2/3 will swap on the same page.

var TCEApplicationNoWaiver = "TCEApplication.aspx"
var TCEApplicationWaiver = "TCEApplication.aspx"
var TCEApplicationNotEligible = "TCEApplication.aspx"

if (window.location.href.toLowerCase().indexOf(TCEApplicationNoWaiver.toLowerCase()) >= 0) {
            $("#IncludeCMSContent1").load("http://www.example.com/tce-application-noWaiver.htm #externalContent");
}
else if (window.location.href.toLowerCase().indexOf(TCEApplicationWaiver.toLowerCase()) >= 0) {
            $("#IncludeCMSContent2").load("http://www.example.com/tce-application-Waiver.htm #externalContent");
}
else if (window.location.href.toLowerCase().indexOf(TCEApplicationNotEligible.toLowerCase()) >= 0) {
            $("#IncludeCMSContent3").load("http://www.example.com/not-eligible.htm #externalContent");
}
1
  • 2
    remove the else? Your statement will only trigger one of those cases currently Commented Jul 28, 2016 at 14:07

1 Answer 1

2

Remove the else statement so all the conditions will be triggered:

if (window.location.href.toLowerCase().indexOf(TCEApplicationNoWaiver.toLowerCase()) >= 0) {
    $("#IncludeCMSContent1").load("http://www.example.com/tce-application-noWaiver.htm #externalContent");
}

if (window.location.href.toLowerCase().indexOf(TCEApplicationWaiver.toLowerCase()) >= 0) {
    $("#IncludeCMSContent2").load("http://www.example.com/tce-application-Waiver.htm #externalContent");
}

if (window.location.href.toLowerCase().indexOf(TCEApplicationNotEligible.toLowerCase()) >= 0) {
    $("#IncludeCMSContent3").load("http://www.example.com/not-eligible.htm #externalContent");
}

Hope this helps.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.