javascript: Loading external urls in jqModal jquery plugin
I was introduced two years ago to the jQuery javascript library via the thickbox script which, among other things, allows to load external urls inside a modal window, a neat feature enhancing user experience as it provides a more visual continuity between the current window and the next.
jQuery is a surprisingly easy library to get your hands on, even for designers and server-side developers such as me, and as I used it more and more in my every day development, quickly grew in me emotions and feelings of true love towards this splendid library and its outstanding user community. Pop into the mailinglist, you will be amazed by the number of souls dedicated to helping each other. Some politician leaders should learn from it (is there a jquery plugin for solving the everlasting Belgian political crisis ? could be fun
)
Anyway, among the zillion jquery plugins, one such plugin offers a much more powerful and flexible way to launch modal windows: jqModal.
At first jqModal may not seem as easy to use for novices (unlike thickbox which basically only requires you to add a class to all links that should load into the modal window, thus staying clear of javascript, how convenient). The truth is, once you get your first attempts working, jqModal is just as easy, it just needs the designer to mentally "accept" dealing with a little bit of javascript.
Yet, although quite well documented, the jqModal plugin website does not describe the precise use-case of loading into an iframe, so here is a rundown on how I do it.
The final result of thickbox > jqModal example is in action here
1./ html header:
Include the jqModal script and stylesheet in your header. Make sure you have jquery too !
2./ the html describing the modal window structure
jqModal let you define your own modal window html, and uses special classes, such as .jqmClose, which defines a button with a close functionality. (Note that you don't have to provide the html for the modal layer itself. ) Since we want to load an external url, we will use an IFRAME as container. As a habit, I usually put modal window html code at the very end of the body element.
3./ the css
Include the jqModal css properties and customize to your liking So, in addition to the jqModal stylesheet, i added this styling:
-
.jqmClose{ background:#FFDD00; border:1px solid #FFDD00; color:#000; clear:right; float:right; padding:0 5px; cursor:pointer; }
-
.jqmClose:hover{ background:#FFF; }
-
#jqmContent{ width:99%; height:99%; display: block; clear:both; margin:auto; margin-top:10px; background:#111; border:1px dotted #444; }
4./ the javascript
Add the following to your $(document).ready event handling function:
-
var loadInIframeModal = function(hash){
-
var $trigger = $(hash.t);
-
var $modal = $(hash.w);
-
var myUrl = $trigger.attr('href');
-
var myTitle= $trigger.attr('title');
-
var $modalContent = $("iframe", $modal);
-
-
$modalContent.html('').attr('src', myUrl);
-
//let's use the anchor "title" attribute as modal window title
-
$('#jqmTitleText').text(myTitle);
-
$modal.jqmShow();
-
}
-
// initialise jqModal
-
$('#modalWindow').jqm({
-
modal: true,
-
trigger: 'a.thickbox',
-
target: '#jqmContent',
-
onShow: loadInIframeModal
-
});
-
-
});
Basically, the loadInIframeModal function controls what should happen when a jqModal is to be shown: here, it assigns the clicked link's URI to the IFRAME SRC attribute, thus loading the link inside the jqModal iframe, updates the modal title and then reveals the modal.
Then, the jqm() call initializes the jqModal DOM object, specifying that it should be a modal behaviour (nothing clickable outside the window itself), it will be launched by anchor links with class "thickbox", and the result will be loaded in the iframe with id "jqmContent".
It wasn't too difficult wasn't it ? I told you jqModal is flexible. In fact, i think it's the swiss-army knife of all modal windowing !
Converting your website from thickbox to jqModal
I used thickbox on a very large Content Management website, but wanted to get the snappier feel of jqModal.
Not too difficult, except that thickbox parameters are included in the href attribute itself, as additional query vars.
Here is an example of such url:
-
writing.php?todo=display&writing_id=2&KeepThis=true&TB_iframe=true&width=90%&height=99%
In this example, the thickbox parameters are KeepThis,TB_iframe,width and height, which i had to translate into something jqModal could manage. The parameters i was particularly interested in are the "width" and "height", allowing to modify the jqModal window dimensions.
Therefore I created a wrapper function that would look into the querystring for the width and height parameters, and modify the window accordingly.
Note that i wanted the modal window to always stay in the middle of the screen, so redimensioning it means also modifying its position on the screen.
this explains the long code. And also the will to accomodate for percentage resizing (such as in the example above : "width=90%").
Now, it's quite bloated but it works, ok ?
See the thickbox > jqModal example in action here
All suggestions for improvement are welcomed though.
12 OCTOBER 2008 UPDATE: Added a new query vars, that specify if the parent window should be reloaded or not: jqmRefresh (default to true in this case)
-
$(document).ready(function(){
-
//thickbox replacement
-
var closeModal = function(hash)
-
{
-
var $modalWindow = $(hash.w);
-
-
//$('#jqmContent').attr('src', 'blank.html');
-
$modalWindow.fadeOut('2000', function()
-
{
-
hash.o.remove();
-
//refresh parent
-
if (hash.refreshAfterClose == true)
-
{
-
window.location.href = document.location.href;
-
}
-
});
-
};
-
var openInFrame = function(hash)
-
{
-
var $trigger = $(hash.t);
-
var $modalWindow = $(hash.w);
-
var $modalContainer = $('iframe', $modalWindow);
-
-
var myUrl = $trigger.attr('href');
-
-
var myTitle = $trigger.attr('title');
-
var newWidth = 0, newHeight = 0, newLeft = 0, newTop = 0;
-
$modalContainer.html('').attr('src', myUrl);
-
$('#jqmTitleText').text(myTitle);
-
myUrl = (myUrl.lastIndexOf("#")> -1) ? myUrl.slice(0, myUrl.lastIndexOf("#")) : myUrl;
-
var queryString = (myUrl.indexOf("?")> -1) ? myUrl.substr(myUrl.indexOf("?") + 1) : null;
-
-
if (queryString != null && typeof queryString != 'undefined')
-
{
-
var queryVarsArray = queryString.split("&");
-
for (var i = 0; i <queryVarsArray.length; i++)
-
{
-
if (unescape(queryVarsArray[i].split("=")[0]) == 'width')
-
{
-
var newWidth = queryVarsArray[i].split("=")[1];
-
}
-
if (escape(unescape(queryVarsArray[i].split("=")[0])) == 'height')
-
{
-
var newHeight = queryVarsArray[i].split("=")[1];
-
}
-
if (escape(unescape(queryVarsArray[i].split("=")[0])) == 'jqmRefresh')
-
{
-
hash.refreshAfterClose = queryVarsArray[i].split("=")[1]
-
} else
-
{
-
hash.refreshAfterClose = true;
-
}
-
}
-
// let's run through all possible values: 90%, nothing or a value in pixel
-
if (newHeight != 0)
-
{
-
if (newHeight.indexOf('%')> -1)
-
{
-
-
newHeight = Math.floor(parseInt($(window).height()) * (parseInt(newHeight) / 100));
-
-
}
-
var newTop = Math.floor(parseInt($(window).height() - newHeight) / 2);
-
}
-
else
-
{
-
newHeight = $modalWindow.height();
-
}
-
if (newWidth != 0)
-
{
-
if (newWidth.indexOf('%')> -1)
-
{
-
newWidth = Math.floor(parseInt($(window).width() / 100) * parseInt(newWidth));
-
}
-
var newLeft = Math.floor(parseInt($(window).width() / 2) - parseInt(newWidth) / 2);
-
-
}
-
else
-
{
-
newWidth = $modalWindow.width();
-
}
-
-
// do the animation so that the windows stays on center of screen despite resizing
-
$modalWindow.css({
-
width: newWidth,
-
height: newHeight,
-
opacity: 0
-
}).jqmShow().animate({
-
width: newWidth,
-
height: newHeight,
-
top: newTop,
-
left: newLeft,
-
marginLeft: 0,
-
opacity: 1
-
}, 'slow');
-
}
-
else
-
{
-
// don't do animations
-
$modalWindow.jqmShow();
-
}
-
-
}
-
-
$('#modalWindow').jqm({
-
overlay: 70,
-
modal: true,
-
trigger: 'a.thickbox',
-
target: '#jqmContent',
-
onHide: closeModal,
-
onShow: openInFrame
-
});
-
});
I hope that you enjoyed the read, let me know if you have any questions, ok ?
Author: pixeline
Date: July 1st, 2008
filed in: Development, General, SEO
Follow the discussion on this entry via RSS 2.0 feed.
Hey. Just what I was thinking about doing, too. Thanks!
BTW the "keepThis=true" param in the Thickbox queryString is just there to illustrate that the parameters Thickbox cares about should come at the end of the query string.
Bruce
I really appreciate this writeup. I've wondered for awhile now how to handle iframe content in jqmodal.
One question: Why did you choose jqmodal over the new ui.dialog? I'm wanting to switch from thickbox myself, but I'm leaning towards the ui.dialog control since it seems that will be the more "official" way of doing modal windows for jquery. Was there a specific reason you chose jqmodal over ui.dialog?
@travis : you got me there
I haven't even looked at ui.dialog yet. I'm just a bit afraid to use something that is as new, and i have been already using jqModal in ajax mode on other projects. So it's a matter of personal preferences. Besides, i know that jqModal's code is so well done and so flexible i will never be "locked" to it, like i was with thickbox. jqModal allows to do *anything" modal, provided you understand its structure. hope this clarifies a bit...
Hi John,
Regarding 1./
indeed you could use a DIV instead of an IFRAME, you'll find plenty of examples on the jqModal page: http://dev.iceburg.net/jquery/jqModal/
The interest about using an iframe is to use external pages, meaning, not sitting on the same domain.
2./ i would not use an iframe for your case, but feed the modal content via ajax. using an iframe in the use case you describe is awkward since if the user leaves its computer open for an hour (for example), his session may time out, but still he'd be able to interact because the iframed page does not check for his session. It's really not the best way to do it, use jqModal with ajax calls, and each ajax call should first and foremost check if the user is authorized. See brice's page for examples, it's not really complicated and ajax is the web dev methodology to achieve exactly what you want: desktop responsiveness on the web.
HTH !
Thank you very much for the fast and excellent response! I will indeed follow your advice. As a newbie, I prefer to learn the best way to do things and you have pointed me in that direction.
Sincerely,
John
Glad i could help. Make sure you check the jquery.form plugin by Mike Alsup , very useful for quick and easy ajaxing.also, connect to the jquery google group for any jquery related help you may need. The jquery community is fast and very friendly. We've all been rookies
Is there a way to make it open without animating?
Also, I notice (in FF) that it animates the first time after the page is refreshed... but if you close the window and open it again (and repeat), the animation doesn't take place.
@courtney: sure, this is all coded in jquery. Replace animate() by the .css() function (adapt so that the syntax of the function .css() is correct ).
about your second comment: it animates only if the passed width/height arguments are different values than the current modal window width/height value. When you say it is "closed", it would be more correct to say it is hidden, that's why the animation doesn't take place: because closing it just makes its css property "display" set to "none". am i being clear?
Hi Alexandre,
I am trying to learn jQmodal from your example and using firebug. When I edit the html and replace the link to your article (or any of the links) with a link to my web page (www.marymonte.com) and then click on the link in the page, it opens my page rather than opening the jQmodal window. I do not understand what is going on there. I expected to see my page inside the modal window just like yours. Can you please explain?
Thank you,
John
Thank YOU!!!
john, please post a link tat i can check your code !
I've tried to implement this verbatim, but unfortunately the modal isn't showing up on top of my page, it's actually showing up above my page : (
Any ideas? Is there a secret prereq that the main body be relatively positioned or something in the CSS?
Hey i tried using ur example but for some reason the $modal.jqmShow() did not work i had to use a simple hash.w.show().....kinda weird....the only explanation i found is that the jqmShow function changed in the .js i got which is the version 2008.07.06 +r13.
any how here is the scrip i used to define the Modal
var loadInIframeModal = function(hash){
var $trigger = $(hash.t);
var modal = $(hash.w);
var myUrl = $trigger.attr('href');
var myTitle= $trigger.attr('title');
var $modalContent = $("iframe", modal);
$modalContent.html('').attr('src', myUrl);
$('#jqmTitleText').text(myTitle);
modal.fadeIn('2000');
};
var myClose = function(hash){
hash.w.fadeOut('2000', function(){
hash.o.remove();
});
};
$('#modalWindow').jqm({
modal: true,
trigger: 'a.thickbox',
target: '#jqmContent',
onHide: myClose,
onShow: loadInIframeModal
});
@jon, try changing the doctype of your html document. Otherwise, post a link so that i can see it for myself.
I too am seeing problems with this script. The main one is that the modal never shows. For some reason the display attribute style is still set to 'none' on jqmWindow. The background overlay comes up just fine. Setting the display style to 'block' with Firebug works, but there's obviously an issue still.
Any suggestions?
Hi, enjoying your code... would like to ask how to clear the content of the modal iframe before loading it with a new URL, as it seems to first show the last URL loaded before fetching the new one... thanks.
Alexandre,
For some reason, I don't seem to be able to get the title attr to work.
Its as if the title is not being passed in $(hash.t)
Any idea's ?
Using: jQuery 1.2.6, jqmodal 07/06/2008 +r13
TIA
Sean
ps. Setting the .animate({...},1); seems to work as a quick way to avoid animation.
I see that changing the href's width and height will cause the modal window to animate to the new size from the last used size. Been trying to figure out how to get it to animate from, basically width=0 and height=0, so that the full animation happens each time. I tried various var declarations in the jqmClose to no avail. Any ideas? Thanks.
@brian, sean & yoyo: post a link please
@yoyo: try setting the iframe "src" attribute to "blank.html" before showing it.
@dmayo2:
try to change the line
$modal.jqmShow().animate({
to
$modal.css({width:0, height:0}).jqmShow().animate({
@pixeline... thx ... got it to work using a similar option...
@pixeline, its on an intranet at the mo. Will have to work something out !
I apologize for this being offtopic. I found your great blog after reading the following question you posted on the InnerFade jQuery plugin page.
I would like to do exactly the same thing. Did you ever find or devise a solution? Many thanks if you are able to reply.
Forgive me for asking, but I don't understand the syntax of the following two statements:
var $trigger = $(hash.t);
var $modal = $(hash.w);
Can you please explain to me what .t and .w are? I've never seen these before in Javascript. Is this specific to jQuery? I'm fairly new there too. Are these shortcut references?
@ggianop: these "t" and "w" are part of the jqModal plugin, which uses a hash object to describe the modal window. t refers to "trigger" and w refers to the modal window container .
Your question is a good question, as it's a recurring comment that these variables are not very user friendly : Brice Burgess, the jqModal plugin author, is aware of it and plans on improving that.
Ok, I know this will raise an "asked and answered" objection, but I debugged the code and answered my own question. These (.t & .w) are properties of the jqModal class.
However, I debugged the code because it was not working. There is a bug in this Thickbox conversion code in openInIframe(). The lines that extract myUrl and queryString need to be reversed. They are currently written as:
myUrl = (myUrl.lastIndexOf("#") > -1) ? myUrl.slice(0, myUrl.lastIndexOf("#")) : myUrl;
var queryString = (myUrl.indexOf("?") > -1) ? myUrl.substr(myUrl.indexOf("?") + 1) : null;
But the order needs to be reversed to:
var queryString = (myUrl.indexOf("?") > -1) ? myUrl.substr(myUrl.indexOf("?") + 1) : null;
myUrl = (myUrl.lastIndexOf("#") > -1) ? myUrl.slice(0, myUrl.lastIndexOf("#")) : myUrl;
The problem is the value myUrl is being truncated to the left of the # mark before the query string is extracted from the same variable. Therefore the query string is always null if a # URL fragment is specified in the target URL. The line assigning to myUrl is modifying the very string used to attempt to obtain the queryString; therefore you must pull the queryString first.
i have the same problem with @manule and @brain
here is debug code:
----------------------------------------------------------------------------------------------
jqModal :: Minimalistic Modaling for jQuery
.jqmClose {
background:#FFDD00;
border:1px solid #FFDD00;
color:#000;
clear:right;
float:right;
padding:0 5px;
cursor:pointer;
}
.jqmClose:hover {
background:#FFF;
}
#jqmContent {
width:99%;
height:99%;
display: block;
clear:both;
margin:auto;
margin-top:10px;
background:#111;
border:1px dotted #444;
}
$().ready(function() {
var loadInIframeModal = function(hash){
console.log(hash);
var $trigger = $(hash.t);
var $modal = $(hash.w);
var myUrl = $trigger.attr('href');
var myTitle= $trigger.attr('title');
var $modalContent = $("iframe", $modal);
$modalContent.html('').attr('src', myUrl);
//let's use the anchor "title" attribute as modal window title
$('#jqmTitleText').text(myTitle);
$modal.jqmShow();
}
// initialise jqModal
$('#modalWindow').jqm({
modal: true,
trigger: 'a#view',
target: '#jqmContent',
overlay: 12,
onShow: loadInIframeModal
});
});
view
Close X
Title of modal window
-----------------------------------------------------------------------------------------
any suggestion?
all: please please please post a link with your bug instead of posting the raw code in the comments. i don't have the time to reconstruct examples out of what you write. thank you
I had the same issue as some other people on here where the grey modal area would come up, just not the box containing the content. The fix was:
//$modal.jqmShow();hash.w.show();
I dunno what the actual issue is, this makes it work though.
Thanks Person. I set up according to instructions above and then had the same problem, and this change worked for me too.
Thanks, Pixeline, too, for doing a great tutorial on something I would never have figured out on my own!
I love your code and it works great! But I'm having a bear of a time trying to get the modal window to close itself -- with no user interaction.
I've got a little form in the modal. Users submit it and it should come back and close itself. But I can't figure out how to call a JQuery function in a parent -- from it's child (the iframe). I've tried dozens of referencing combos -- no luck.
If I add an ID to the "Close" link (the link with the jqmClose class), I could get it to close in IE by generating this JS when the submitted form page came back:
window.top.document.getElementById("my ID goes here").click();
Unfortunately, this won't work in FireFox. And creating a "MouseEvents" in FireFox simply causes it to crash (on all my computers).
How can I call a JQuery function from the child in the parent?
Thanks!!
@meyers: You should be able to reference a function in the parent page like this:
window.top.functionName();
So for hiding a jqmodal pop-up, it should be:
window.top.jqmHide();
Travis,
Thanks much for the very prompt reply. I thought: "Could it be so simple? Did I miss that?" Unfortunately, it returns the usual: "window.top.jqmHide is not a function".
I put up a demo for you to see: http://www.symliving.com/test/index.php
And a link on that page to a .zip with the source.
If you look at the JS returned when the modal form refreshes, you can see the JS code I left in there (commented out) that "works" -- in a haphazard way. I'd like to replace it with proper code.
Ideas?
Again, I really appreciate your help.
My apologies. I haven't actually used jqModal, so I was slightly unfamiliar with it's methods. I believe the following should work for you:
$("#editModalW", top.document).jqmHide();
When I load a new url in the jqmodal window the previous page called shows while the new one is being fetched. I am using an ajax call to get the content. @YOYO reported this issue and claimed to resolve it. I would love to know how to get around this unwanted behavior. I am not using an iframe. I have done a bunch of searching with no luck.
Any suggestions?
Hello mate! awesome work thanks a lot you save the day!!, i have a question about the position and the size of the dialog, theres a way that i can change it??
Thanks in advance!!
Meyers,
Were you ever able to find a solution? I am in a similar situation and Travis' fix did not seem to work. Thanks.
-Ray
Ray,
Nope, sorry. Had to roll my own.
-Meyers
Meyers and Ray,
this should work for what you want to do:
1. create a function on the page that has the modal (we'll call it closeMyWindow)
2. do whatever you need in the func, then at the end do: $('#YourModalID').jqmHide();
3. on the page that gets loaded in the iframe, call window.parent.closeMyWindow() somewhere (feel free to add params to the func and pass data around)
works fine for me in IE and FF. Hope that helps.
I am getting the same bug as some of the previous posters.
Thought when i change
$modal.jqmShow()
to
hash.w.show()
I dont get the animation and resizing.
Any knownn fixes?? Thanks
@karl: make sure you call show() BEFORE you actually animate(). OTherwise, post a link...
Link is located on digitaldorf.com
Click on any of the links in the left column. That is what is happening when i leave the code at $modal.jqmShow()
Thanks!
[...] Tutorial describing loading external content into IFRAME [...]
I can't put the refresh to work. I've used the script and it's working fine, spite of the refresh page part.
@friend: without a link i can't help much...
This is really great, thank you for your efforts. I was able to follow your example and produce my page. But I need to call this as a function instead of a href link.
I am planning to use this code in conjunction with Google Maps and want to add the fnction in this line:
GEvent.addListener(polyg2,"click",function()(.....)
Can someone help me how to call this using a javascript function?
Thank you,
G
How would i go about setting the window to a certain % height and width?
@karl: in the link that will launch the jqModal, add as query vars width=90%&height=45%
so
microsoft
Look at the example page's source code if you need further help: http://www.pixeline.be/experiments/ThickboxToJqModal/
Well, what i would like to do, is have the percentages in the script. If possible i would like to have nothing in the href for the link, because with some of the pages I load up, it bugs them out.
Is there any way i can set the percentages in the script?
im an idiot. figured it out! Thanks~!
Sorry for not posting links, but i'm developing an intranet, and for the moment it's not possible to do that.
The problem I have is that when I add a new record the parent page should reload to show the new line, but it doesn't. I tried to debug by uncomment the line:
$('#jqmContent').attr('src', 'blank.html');
but it doesn't get there. Don't know what i'm doing wrong.
I'm using this script before the update and the rest works fine, but not the change!
@friend:
check the example page, i've added an example that refreshes the page when you close the modal window. Compare the source code with your code.
http://www.pixeline.be/experiments/ThickboxToJqModal/
Hi,
Firstly I'd like to say Excellent Work. Ths is really some nifty stuff.
However I am wondering about letting the iframe based modal load as soon as the DOM loads. It would be nice to have your popup come up as the page is loaded.
@dan: thanks for the idea, sounds good, but i wonder if it is at all possible. 2 theoretically possible ways:
- if you have editing access to the loaded page, you could put the jqmShow() call inside that one, so on document.ready of the loaded content, the modal window would show up.
- second possibility involves javascript in the main window having access to the loaded content in the iframe, to know when it has finished loading its DOM. I'm not sure crosssite policies allow this, but would have to experiment to be sure.
Hi, thanks for the quick reply.
I'm not quite sure I am following your suggestions.
To re-iterate, it would be great to have functionality where on document ready of the main window, the iframe automatically pops up with a preconfigured URL. Just as if someone clicked on an iframe popup trigger.
I tried just taking the open function and manually stuffing in the variables at the beginning, but I'm not sure if the modalWindow is supposed to be the id of the div "#modalWindow" or the target of the popup. Also I wonder if this isn't working because I need to pass the hash, which I have no idea of doing.
It would also be great to have the Title of the #modalWindow change as the iframe's content changes.
@dan: oh, ok i understood something different.
If you want to have the modal window displayed with a url loaded in the iframe on page load,
it's as simple as setting that start url in the src attribute of the iframe, then calling
$('#modalWindow').show(); in your document.Ready call...
See it here: http://jsbin.com/olice/ (mess with the code here: http://jsbin.com/olice/edit/)
Hello again,
thanks for the response!!! Very helpful, but how can we close the window now? I noticed the window wont close.
Can you use something other than an href link as a trigger for the modal? I have some standard form input buttons that I want to use as the trigger for the iframe modal. Possible?
bryan lewis: look for "trigger: 'a.thickbox'," in the code. The trigger option is what you are looking for. Put instead trigger: 'input' and all your buttons will launch the modal.
Hello,
I am very new with jQuery so i am sorry if i am being troublesome.
But i ask you if you please can help me.
How do i disable the animation and set a specific size on the box, but still keep it centered?
Thank you very much for the plugin, it is great!
And thank you for any help!
Hugs, Miria!
Very nice one. Got one question.
It seems that the website in the iframe is still being loaded on the background of the parent page even if you closed the popup window. Is there any way to stop that? Or the refresh parameter is designed for this?
I have the same question than @Miria
I'm trying to solve it by myself but if you can give me a hand, I'd really appreciate it
Thanks for the plugin!
hi,
how do you close the modal window from iframe's content?
say src="/mycode.php", i have a close button in mycode.php.
when user clicks it would close the modal window that holds the iframe.
is it even possible?
thanks
Try this:
in the page loaded inside your iframe, add something like:
You can check the demo page, i've added a working example: http://www.pixeline.be/experiments/ThickboxToJqModal/
[...] - bookmarked by 1 members originally found by LunaBloom on 2008-12-04 javascript: Loading external urls in jqModal jquery plugin http://www.pixeline.be/blog/2008/javascript-loading-external-urls-in-jqmodal-jquery-plugin/ - [...]
Hello - thank you very much for this detailed writeup.
I was using ThickBox for my little application, but in Safari and Chrome the popup window would load behind and below lots of my content - here is my situation:
I have made a page that has a header, an ajax_content window and then controls for the content window. It functions much like a slideshow (forward, back, etc) but instead on only pictures it is loading from external html files.
In one of my external html files I want to have a link that I would like to have pop open a googlemap embeded in an iframe. Thickbox was working fine in IE and FF...but in Chrome and Safari, like I said it opens in behind and below the ajax window.
I am including the javascript, css, and the jqModal dialog in the external html page I load. And jqModal works just fine in IE and FF when I use it like this, but again it loads behind and below the ajax window when I try it in Chrome and Safari.
Any help on this would be greatly appreciated. Please let me know if I have been unclear on something - I'm pretty new to all this stuff.
Jack, can you put a url i can look at ?
Sure, would there be a way I could send it to you as a Private Message or over email?
I only ask because its part of a personal website.
Hi,
Congrat for your great work. I have a problem using JQModal, i read a lot but I didn't found the right solution.
Here is what I am trying to do:
I have a function abcd(url) which loads innerHTML with a link for modal window(with class thickbox)
And it doesn't works. Could you please have some solutions?
Thanks!!
i'm no mind reader so please post a url so i can check your code. thx
Thanks for your reply. Actually, I am trying to do this:
http://stanei.com/ovidiu/www/explorertv/destinations/index.php
I have a grid with subgrid(information from grid, subgrid is dynamic). From subgrid I am trying to open a modal. It works for the first subgrid loading, if I am loading another one it will not work.
Do you have some suggetions, please?
Thank you!!
well make sure the newly loaded thickbox links do get the event attached.
I think the newly links are ok. Or I must add some to onclick=...?
Thank you!!
Good stuff Alexandre. I have been extensively using your plugin these days. I discovered a small flaw in the implementation though. If I specify an "onHide" handler for my "modalWindow", the function gets triggered but does not cascade to its original behaviour of closing the modalWindow.
This is my usage -
$('#modalWindow').jqm({
modal: true,
trigger: 'a.actionButton',
target: '#jqmContent',
onShow:loadInIframeModal,
onHide: garbageCollect
});
my function "garbageCollect" gets called, but the "jqmHide" is not triggered on my modal window. The fix it seems to me lies in the "close()" function where
if(h.c.onHide)h.c.onHide(h)
needs to change to
if(h.c.onHide){h.c.onHide(h);h.w.hide();if(h.o)h.o.remove();}
Nice plugin
Hi Avlesh, please note that this is not my plugin, i'm merely using it
The plugin is by Brice Burgess and can be found on the jqModal page.
I would suggest you send this nice bug fix to him. Thanks !
Alexandre
You did the needful
Hi,
Great works. I have problems with IE7, all the css of the page loaded with the iframe are modified. Any Clue ?
Stephane
Hi
Great plugin dude..
.. BUT! in ie6, can't get the fixed heigt to work, i've tried the fix in the css file, but it dosn't seems to work ?
I know that position:fixed dosn't exist in ie6.
Have you tested your plugin in ie6 ? it dosn't seems to work on your demo page either ?
The demo page works fine for me in Internet Explorer 6. can you post a screenshot of what it shows to you?
Also, maybe try upgrading to the latest jquery version (1.3.2 at the time of writing). jqModal has also been recently updated.
But as i said, it works for me in IE6 (although it's painfully slow to render)...
Yeah it is working fine here, but not when u scroll if u resize the window to a smallere one and open the jqModal window.
The jqModal window should now stay in place even if u scroll in the background. <--- that work in ie7 and FF.
that is a problem because if u scroll down on a page to click a link to the jqModal window, u only see the transparent background.. NOT user friendly
try it self ?
ah ok, i see it now. Mmmh, will need to take of that but i got no time for the moment. If you can find a solution, i'd be glad to update the script.
it may have been that i dumped this css out of the jqmodal.css file. If you put it back in :
it should work...
We found a solution that work.
It's look a bit like yours but with som changes, could be nice if u could implementate it into yours script!
look at this tutorial we used http://www.howtocreate.co.uk/fixedPosition.html
can't seem to make it work like that. will have to postpone the fix until later.
Hi,
great script and I'm using it extensively in a project, but am having a hard time refreshing the content IN the iframe from a link in the parent window w/out first having to close the modal window....I have a navigation on a page with triggers that open the modal window to specific pages in the iframe it contains, but want to also load those pages from that nav w.out having to close the modal window, I guess, to be more specific.
Ideas?
Hi,
great script and I'm using it extensively in a project. It works great, but I need to do one thing and can't figure it out: I have a nav on a page, and links in the nav open the modal window with content in an iframe. I need to also be able to reload the contents of that iframe in the modal window from the nav while the modal window remains open (or at the very least, close it and reopen it from the nav). Currently, clicking on the items in the nav while the window is open won't do anything. Wondering if I've overlooked a default setting somewhere.
thanks
Hi.
It works nice for me too but only in FF.
I have the same problem Kyle has mentioned in IE7.
The content of the iframe is nicely reloaded while I'm posting the form it contains with Firefox (3.0).
In IE 7 I have a scrollbar which appear at the bottom of the JQmodal and posting its content nothing changes unless I move the mouse on the page that holds the IFrame ???
If I consult the source code in the modal it is ok ???
I'm really wondering what is happening with IE.
Any ideas ?
Hi,
Could you help me.
When I put a link in HTML code everything works fine but when I load the same link via ajax, plugin doesn't work. I don't know where is the problem?
I preapred the MVC classes. I get the content using method like this:
load: function()
{
var self = this;
$.ajax({
type: "POST",
url: this.url,
success: function(msg)
{
var data_obj = eval("(" + msg + ")");
self.rows = data_obj;
self.count = data_obj.length;
self.fire_event(0);
}
});
}
When event is fired then renderer class put all content into div. This content contains link:
. When I click on this link plugin doesn't work.
that's because your event only applies to the DOM available when your event is initially called. You need to call it again whenever you change the dom via your ajax call(s).
typically inside your "success" function. You can also use jquery live() event binder as in $("myEl").live('click',function()..)
hi pixeline, thanx for the script.
I'm using the example http://www.pixeline.be/experiments/ThickboxToJqModal/, (If you wonder what this page is about, how about reading the dedicated blog post ? ), i used copy/past the entire code, because the steps you set abouve didn't work (they need tweeking; if you copy/past the code abouv this page it doesn't work, it would be better if you add another textfield here you past the complete code.)
I tried to delete the animation but, it doesn't work; i copied $modalWindow.jqmShow();
instead of
$modalWindow.css({
width: newWidth,
height: newHeight,
opacity: 0
}).jqmShow().animate({
width: newWidth,
height: newHeight,
top: newTop,
left: newLeft,
marginLeft: 0,
opacity: 1
}, 'slow');
try it yourself and u will see.
second question; is it possible to call the modal box from a function? instead of a link?
thank you, keep the good work man!
is it possible to call j
Perhaps I'm confused but does this require Thickbox to work?
[...] This post was mentioned on Twitter by javascript:, javascriptstories. javascriptstories said: pix.l|ne 's Journal » Blog Archive » javascript: Loading external urls in jqModal jquery plugin: http://bit.ly/dvESYO [...]
[WORDPRESS HASHCASH] The comment's server IP (208.74.66.43) doesn't match the comment's URL host IP (74.112.128.10) and so is spam.
How do I change the size of the Block?
thanx for information and plugins...
Can I call HTTPS to the Modal window
Can a jqModal window that loads external content be made draggable with jqDnR.js? The examples I have found do not address this specific case and my attempts to make it draggable have failed.
Thanks for any information you can share about this.