I run an e-commerce website where the following function is defined. I don’t control the template where this function is called. It is used to open a small contact window. The URL changes from session to session. I need to somehow parse that URL out of the function and store in a variable to call it from fancybox using a plain HTML/CSS template that I control. Do you know how I could do this? Here is the function:
function OpenContactWindow() {
window.open('/UI/ContactInfo.aspx?id=R6nq0s8aTFntDzsV-p-pXm22kKpENjtYjAsgwTtIa5Qhhf5CT4Ndx7Rg-e-e', '', 'fullscreen=no,toolbar=no,status=yes,menubar=no,scrollbars=yes,resizable=yes,directories=no,location=no,width=800,height=600');
return false;
}
On the template that I do control, I have a link where the function is called and it opens up in a plain pop up window:
<a href="javascript:void(OpenContactWindow());">Contact Us</a>
This is the code I came up with, but it does not work:
$(document).ready(function(){
$(".extLink").fancybox({
'width' : '75%',
'height' : '75%',
'autoScale' : false,
'transitionIn' : 'none',
'transitionOut' : 'none',
'type' : 'iframe'
});
});
});
<a class="extLink" href="javascript:void(OpenContactWindow());">Contact Us</a>
What is the code I should be using? I’m a newbie! =)
I don’t know anything about FancyBox, but here’s a way to parse out the URL from the function:
Basically, you just convert the function to a string with .toString(), then use a couple of split()s to find the URL. You’ll notice that although the window.open() in the OpenContactWindow function uses single quotes, this uses double quotes. JavaScript automatically replaces the single quotes with the double quotes. As noted, the variable
contactURLcontains the URL from theOpenContactWindowfunction. You should be able to take it from there and use FancyBox however necessary.You can find a demo here. Just click the Get URL button, and it will show you the URL. Check out the source, and you will see that it does in fact check the function. The function uses a random string for the ID, which is generated by PHP each time the page is reloaded. After the button is clicked and the URL is shown, the page is reloaded so you can see it at work again, with a newly generated ID.