0

I have embed a iFrame from a site I want to embed. This iFrame can be called with different parameters in the URL. For example:

1. ?strasse=A1&region=HE
2. ?strasse=A2&region=HE
3. ?strasse=A3&region=HE
4. ?strasse=A1
5. ?strasse=A2&region=NRW
6. (or even without)

Now I created a form on my wordpress start page where you can select exactly those parameters. Now I want, if the use pressed submit that the iFrame gets reloaded but this time with the parameters the user has selected. So, I need to change the src="..." of the iFrame dynamically!

My question now is, how can I do that? - Because it is wordpress I'm struggeling. If it isn't possible with an Ajax request it's not bad. But it would be very nice if we could build an Ajax request...

Has anybody an idea?

Greetings and Thank You!

1 Answers1

0

When the user clicks Submit you just have to change the 'src' attribute via Javascript:

...
onsubmit: function() {
    var url = // construct the URL with the validated data you want to add
    document.getElementById('myiFrame').setAttribute('src', url);
}
...
QuarK
  • 2,306
  • 1
  • 20
  • 24
  • And how can I get the paras from the url? (After pressed submit) – user7422244 May 30 '17 at 11:14
  • from the URL or from the form? if the first: https://stackoverflow.com/questions/901115/how-can-i-get-query-string-values-in-javascript – QuarK May 30 '17 at 11:18
  • But as you can see on my page: http://j-trier.de/stau - it is not working... why? Click "Laden". This Button calls the function loadSrc. This function should normally set the src attribute on the iFrame with the id "stau". But it doesn't work... Do you have an idea? – user7422244 May 30 '17 at 11:31
  • Do not use embed, and use iframe instead – QuarK May 30 '17 at 13:45