This forum uses cookies
This forum makes use of cookies to store your login information if you are registered, and your last visit if you are not. Cookies are small text documents stored on your computer; the cookies set by this forum can only be used on this website and pose no security risk. Cookies on this forum also track the specific topics you have read and when you last read them. Please confirm that you accept these cookies being set.

Widget Iframe change URL Dinamycally
#1
Hello!

I have a widget with iframe inside with external URL.

I want this URL to be direct link trendlog but I want to change this URL depending of the button pressed.

Is this possible? Or do I have to make one widget for each URL?

Thanks!
Reply
#2
You can do this via Custom JavaScript, change #widget-2 to your widget's id, create buttons as needed and set Additional classes to btn-1, btn-2 and so on.

Code:
$(function() {
  function seturl(url) {
    $('#widget-2 iframe').prop('src', url);
  }

  $('.btn-1').off('vclick').on('vclick', function() {
    seturl('https://forum.logicmachine.net');
  });

  $('.btn-2').off('vclick').on('vclick', function() {
    seturl('http://openrb.com');
  });
});
Reply
#3
Lot of thanks!

$(function() {
  function seturl(url) {
    $('#widget-2 iframe').prop('src', url);
  }

  $('.btn-1').on('vclick', function() {
    seturl('https://forum.logicmachine.net');
  });

  $('.btn-2').on('vclick', function() {
    seturl('http://openrb.com');
  });
});

Modified code for my use!

Which is the event to trigger On/Off the Widget?
Reply
#4
Use this to emulate click on the button that opens/closes widget:
Code:
$('.widget-btn').trigger('vclick')
Reply
#5
Thanks Admin!!
Reply


Forum Jump: