0

I'm converting a website in modx which makes use of a java wrapper to dynamically pull in content and display it without any page reloading. the basics of the site are there but I'm having a slight issue with generated links and I'm not sure what the best way to get around it is.

I didn't write the original javascript that the site uses, I'm just trying to refactor it slightly so modx leverages the right pieces.

Here is an example of the template I'm using to page next/previous

 <div id="next"></div>
 <script type="text/javascript">
 $(function() 
    {
    setNext('[[+href]]');
    var page_content_height = $('#page_content').height();
    }
 );
 </script>

Basically modx's generated links take the following format in the page:

 setNext('nb/index.php?id=17&amp;page=2');

For them to work, they need to be:

 setNext('nb/index.php?id=17&page=2');

The sites using jquery, I was thinking there might be a way I can get that to convert text strings before it renders the page?

Hope someone can point me in the right direction cos I'm a bit stumped atm.

Funk247
  • 330
  • 4
  • 22

3 Answers3

1
setNext(htmlDecode('nb/index.php?id=17&amp;page=2'));

function htmlDecode(input){
  var e = document.createElement('div');
  e.innerHTML = input;
  return e.childNodes.length === 0 ? "" : e.childNodes[0].nodeValue;
}

See unescape html entities in javascript

Community
  • 1
  • 1
karaxuna
  • 26,752
  • 13
  • 82
  • 117
0

This would do the trick

var str = 'nb/index.php?id=17&amp;page=2'
str = str.replace(/&amp;/g, '&');
setNext(str);
Jareish
  • 772
  • 2
  • 9
  • 24
  • '&' is html encoded that's why it's showing '&'. different symbols can be encoded, not only '&' (for example '<'). see yourself: http://www.opinionatedgeek.com/DotNet/Tools/HTMLEncode/encode.aspx – karaxuna Mar 16 '13 at 09:55
  • 1
    funk247 asked for & only, so he could generate a list of url params. My answer does that. No need to downvote that. – Jareish Mar 17 '13 at 20:23
  • Yeah, this did exactly what I wanted it to which is why I chose it as the correct answer. – Funk247 Oct 23 '15 at 14:26
0

IMO it would be better to correct it at the source rather than 'patching it up' in the browser.

Worst case, you can do it in PHP like this:

$href = 'nb/index.php?id=17&amp;page=2';
$modx->setPlaceholder('href', str_replace('&amp;', '&', $href));

However if the link was generated using MODX's makeUrl() method then it should already be formatted correctly.

okyanet
  • 3,106
  • 1
  • 22
  • 16
  • been bodging things all for the last 38 years and its never caused me any issues this far! Why change the habit of a lifetime I say :D I shall bear your suggestion in mind for future use though. – Funk247 Mar 08 '13 at 12:56