<script src="https://code.jquery.com/jquery-3.7.1.min.js" integrity="sha256-/JqT3SQfawRcv/BIHPThkBvs0OEvtFFmqPF/lYI/Cxo=" crossorigin="anonymous"></script>
<script>
      (function ($) {

const $iframe = $('#kyHugIframe');
    const thisSiteOrigin = 'https://www.visitmyoldkyhome.com';
    const targetOrigin = 'https://www.kyhug.com'; // kyHugOrigin
    const presavedURL = localStorage.getItem('KYHUGIWURL');

    // Listen for messages specifically from the iFrame
    window.addEventListener('message', function (event) {
        if (event.origin !== targetOrigin) return;
        if (event.data.type === 'urlUpdate') localStorage.setItem('KYHUGIWURL', event.data.url);
    });
	
	const params = new URL(document.location.toString()).searchParams;
	const experienceId = params.get("experience-id");
	console.log(experienceId);
	
	if(experienceId && $iframe.length > 0)
		{
			const oldUrl = $iframe.attr('src');
			if(oldUrl.includes("/experiences-list")) {
				const newUrl = oldUrl.replace("/experiences-list",  "/experience-details/" + experienceId);
				$iframe.attr('src', newUrl);
			}
		}

    $iframe.on('load', function () {
        const iframeWindow = $iframe[0].contentWindow;
        // Send the init message (this site origin string) to the iframe (kyhug) to specify channel of communication
        setTimeout(() => {
            iframeWindow.postMessage({type: 'origin', url: thisSiteOrigin}, targetOrigin);
            if (presavedURL) {
                setTimeout(() => iframeWindow.postMessage({
                    type: 'redirect',
                    url: presavedURL
                }, targetOrigin));
            }
        });
    });



})(jQuery);                    
</script>

<iframe id="kyHugIframe" src="https://www.kyhug.com/w/6675cba4-6017-491f-ac78-4314b92ddcf1/experiences-list" style="width:100%; overflow:auto; height:1500px" frameBorder="0">
</iframe>