Question

when I am setting the src of an iframe dynamically with the following javascript in Wordpress:

jQuery(document).ready(function(){ 
    jQuery('iframe').attr('src', 'http://someurl.com/?originid=PORTAL&tijdsblokstart=1700&datum=2014-05-19'); 
});

The last 2 parameters are not picked up. I know it has someting to do with the encoding of the ampersand, but I tried everything...I'm lost now.

 - &
 - &
 - &
 - creating the whole iframe in jQuery 

The src has to be set dynamically.

Thanks!

Was it helpful?

Solution 2

I fixed my issue by creating a function in an external js-file that generates the url for me. So avoid using the ampersand in the Wordpress editor. I would love to hear if someone comes up with a better solution. http://codex.wordpress.org/Using_Javascript

OTHER TIPS

If your problem occurs in post content, there is no universal solution.

Indeed, the & is replaced by & by the wptexturize function from wp-includes\formatting.php:

// Replace each & with & unless it already looks like an entity.

$curl = preg_replace( '/&(?!#(?:\d+|x[a-f0-9]+);|[a-z1-4]{1,8};)/i', '&', $curl );

It's hooked to the the_content filter in file wp-includes\default-filters.php :

add_filter( 'the_excerpt', 'wptexturize' );

The problem is that you can remove this filter but you will loose a lot of formating done by this huge wptexturize function.

One solution for op would be to find a way to remove the ampersand from the code. To do this, you can use jQuery.param to generate the querystring part of the url:

jQuery(document).ready(function(){ 
    jQuery('iframe').attr('src', 'http://someurl.com/?' + jQuery.param({originid: 'PORTAL', tijdsblokstart: 1700, datum: '2014-05-19'})); 
});

A really dirty solution would be:

  1. to register a filter to execute before the wptexturize one using priority 9 (by default, priority is 10) so it change your ampersand to something really unique that the wptexturize function will not alter

  2. to register a filter to execute after the wptexturize one using priority 11 that changes back your ampersand subtitute to a real ampersand

Here's a workaround that worked for me:

char = '&';
char = char.replace('amp;', '');
console.log(char);
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top