New Community Website

Ordinarily, you'd be at the right spot, but we've recently launched a brand new community website... For the community, by the community.

Yay... Take Me to the Community!

Welcome to the Community Exchange, where community members ask and answer questions about DNN. To get started, just start typing your question below and either select one of the suggested questions or ask a new question of your own.

Why does setting window.location.href from an HTML module only work in Edit mode?

Return to previous page

  • 9/7/2017
  • 4271 Views

Question:

James Maher 7 years ago

I am trying to have the page be refreshed with one or more query parameters after the user clicks a submit input button. To do this, I have embedded a jQuery function in an HTML module. Here it is:

$('#display_graphs').click(function () {

var graph_1 = $('#graph_1').is(':checked') ? 1 : 0;

var graph_2 = $('#graph_2').is(':checked') ? 1 : 0;

var graph_3 = $('#graph_3').is(':checked') ? 1 : 0;

var graph_4 = $('#graph_4').is(':checked') ? 1 : 0;

if (!window.location.href.includes("&graph_1=")) {

window.location.href += '&graph_1=' + graph_1 + '&graph_2=' + graph_2 + '&graph_3=' + graph_3 + '&graph_4=' + graph_4;

} else {

window.location.href = window.location.href.substring(0, window.location.href.indexOf("&graph_1=")) + "&graph_1=" + graph_1 + '&graph_2=' + graph_2 + '&graph_3=' + graph_3 + '&graph_4=' + graph_4;

}

});


This works just fine when I have Edit mode open. It does not work, however, if I close Edit mode, or log out. Is there some security setting that I need to disable to allow the page to be refreshed? Also, is there any alternative way that I could add query parameters to the current URL?

Why does setting window.location.href from an HTML module only work in Edit mode?

James Maher
James Maher 7 years ago
Add an Answer

Answers

Sign In to Participate
Or register to become a member