r2d2 of Speak Creative
2/4/2019 - 9:10 PM

Iframe src from string url

Find a specified url from a string input that converts into the src attribute of an iframe. Example site pabc.org/calendar event details of any ministry event. This script specifically looks at the string content within the CalendarEvent__description div on the detailed view of a calendar event.

function iframify(inputText) {
    var replacedText, replacePattern1, replacePattern2, replacePattern3;

    //URLs starting with http://, https://, or ftp://
    var match = /(\b(https?):\/\/[-A-Z0-9+&@#\/%?=~_|!:,.;]*[-A-Z0-9+&@#\/%=~_|])/gim.exec(
        inputText
    );

    return '<iframe style="" src="' + match[0] + '" />';
}


var $desc = $('.CalendarEvent__description');
$desc[0].innerHTML = iframify($desc[0].innerHTML);