PDA

View Full Version : loading javascript in window not pop up



Eddie
01-07-2010, 02:45 PM
Hi,

I have prochatrooms installed on my site/vb forum, the code they gave opened it up in a pop up window only and they don't know the code to make it open up directly on site.

What would I change or use to make the following code open but not open in a pop up:



window.onload=function() { launchChat(); };


If you need more info, tell me what u need and ill provide it .

Thanks to anyone who replies :)

Eddie

jscheuer1
01-07-2010, 03:51 PM
We would need to at least see the launchChat function. Perhaps the entire thing:

Please post a link to the page on your site that contains the problematic code so we can check it out.

If the pop up is not a true window, it may be difficult. If it is a true window, we can redirect the page that populates it to virtually any window including the present one. If however, as I suspect, it is a pop up division, we could possibly make it take over the page or most of the page perhaps, maybe make it be the page itself, depends upon the code involved.

Eddie
01-07-2010, 06:44 PM
Link to site: http://www.ibass-radio.com/radio/
but u need to register to have the chat room pop up (ive made it auto pop up when ur signed in as a member).. .. guests cant use the chat room .. u can quickly register thru the facebook connect button..

This is the code they provide that i add my own site link to:



<script language="JavaScript">
<!--
var userName = "$bbuserinfo[username]";
var userID = "$bbuserinfo[userid]";
var roomID = "Lobby";
// -->
window.onload=function() { launchChat(); };
</script>
<script language="JavaScript" type="text/javascript" src="http://www.ibass-radio.com/prochatrooms/chat.js"></script>


If is possible .. maybe theres a way to have the chat in an iframe .. but the link at the top of the chatroom when popped up is:



http://www.ibass-radio.com/prochatrooms/index.php?uid=**&uname=*****&room=Lobby


If I can put coding in where it has the *s above .. if the code can pull the members info from the forum it could maybe be done as an iframe if u get me ..

Hope that info helps .. if u need more let me know :)

jscheuer1
01-08-2010, 05:13 AM
Should be easier than I thought, as it's opening a true window. If you want it to open in an iframe, just edit chat.js to look like so (change highlighted):


function launchChat()
{
var xOffSet = (screen.width - 225) / 2;
var yOffSet = (screen.height - 500) / 2;
var features = 'width=900,height=700,toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=0,resizable=1';
var winName = 'prochatrooms';
var chatUrl = 'http://'+location.hostname+'/prochatrooms/index.php?uid='+userID+'&uname='+userName+'&room='+roomID;
myWin = window.open(chatUrl,winName);

function createCoo . . .

Place an iframe on your page:


<iframe name="prochatrooms" src="about:blank" width="300" height="300" scrolling="auto" frameborder="1"></iframe>

The highlighted part is important, the width and height are up to you to determine. The src can be any page, or left as "about:blank", whatever you use there will be displayed to the user unless and until they launch the chat. Scrolling should probably be left as auto, but may be changed to "yes" or "no". The only other option for frameborder is 0 for no border, though ordinary css style may be used to control the border, position, and many other properties of the iframe element. Editing the prochatrooms/index.php file may be required for certain things.

To give the user the opportunity to click on a button or link to launch chat, just give that button or link this event attribute:


onclick="launchChat();return false;"

example:


<a href="#" onclick="launchChat();return false;">Chat</a>

But unless you remove:


window.onload=function() { launchChat(); };

the chat (assuming we've done this right) will load in the iframe on page load anyway.

Now, if you want the chat to take over the entire page. That's even easier, just change (in chat.js again):


function launchChat()
{
var xOffSet = (screen.width - 225) / 2;
var yOffSet = (screen.height - 500) / 2;
var features = 'width=900,height=700,toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=0,resizable=1';
var winName = 'prochatrooms';
var chatUrl = 'http://'+location.hostname+'/prochatrooms/index.php?uid='+userID+'&uname='+userName+'&room='+roomID;
window.location.replace(chatUrl);

function createCoo . . .

But if you do that, the cookie will probably not get set, so you would want to put that part first in the code:


function launchChat()
{
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
createCookie('login','login',1);

var xOffSet = (screen.width - 225) / 2;
var yOffSet = (screen.height - 500) / 2;
var features = 'width=900,height=700,toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=0,resizable=1';
var winName = 'prochatrooms';
var chatUrl = 'http://'+location.hostname+'/prochatrooms/index.php?uid='+userID+'&uname='+userName+'&room='+roomID;
window.location.replace(chatUrl);
}

There may be a link or button on the prochatrooms/index.php page that is for closing chat. You may want to remove it or change it. If you are having the chat take over the window (as opposed to launch in an iframe) you may want to change it to have an event such as:


onclick="history.go(-1);return false;"

Eddie
01-08-2010, 10:36 AM
John .. ur an absolute star ..ive spent couple of months trying to do this with no success even from prochatrooms themselves and vbulletin. Thank you very much for your help :)

I now have it in iframe loaded on the front page of the forum :) thank you

Question on the 2nd part you left about it taking over the whole page instead of in an iframe, can you explain what you mean by that, not too sure lol.

Also adding a cookie, would that mean (if it was taking over the whole page) when you refreshed the page the previous chats would remain in the chat room and not disappear when you reload the page?

Eddie
01-08-2010, 10:49 AM
hmmm one thing im noticing, is that its taking forever to load fully in internet explorer, but loads fine in firefox...not because of what we've just done, but wondered if you might know why too?

Thanks

Eddie

jscheuer1
01-08-2010, 11:03 AM
The cookie doesn't appear to store much information. You could play around and see what happens and/or ask the prochat folks.

Taking over the whole page would be just that. Instead of an iframe or pop up, the page would become the chat. Not such a hot idea for the index page.

IE often takes longer to load things than other browsers. But there might be some reason this is (as you seem to be saying it is) taking a particularly long time. For specifics on that I would have to get back to you if I find anything concrete.

Eddie
01-08-2010, 11:31 AM
okay .. thanks for your help on this, I'll try speak to prochatrooms and see about the cookie thing, ill leave as an Iframe as all is working nicely now. If you do find anything out about the loading time on IE if you don't mind letting me know..

Appreciate the speedy and very helpful replies you've given .. thanks again John :)

jscheuer1
01-08-2010, 01:01 PM
To save me some time, did the chat take longer to load in IE when it was a pop up? How much longer is it really?

Eddie
01-08-2010, 02:18 PM
well i just did a test .. and literally for the chatroom to work it takes 3mins 40 secs before u can actually type in it .. only on internet explorer..

and yeh it has taken roughly the same time when it was a pop up

preferably i wish all my members were on firefox as this loads up straight away .. but that wont happen lol ..

any suggestions?

jscheuer1
01-09-2010, 11:21 AM
I just did a test and it took me like 30 seconds, if that, in IE 7.

legolax
06-12-2010, 09:47 AM
I reviving an old post because i needed some help on this matter.
I have installed prochatrooms in joomla but i cant make an iframe to display the chat in an artichle. I can still access chat in another window, but when i try to acess the chat inside the main page with the iframe, i get this message:

Members Only. Please login via the website.

I have made what jscheuer1 recommended, but doesnt work with me, something is missing.

This is the code that i have in the chat.js:


function launchChat()
{
var xOffSet = (screen.width - 225) / 2;
var yOffSet = (screen.height - 500) / 2;
var features = 'width=900,height=700,toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=0,resizable=1';
var winName = 'prochatrooms';
var chatUrl = 'http://'+location.hostname+'/prochatrooms/index.php?uid='+userID+'&uname='+userName+'&room='+roomID;
myWin = window.open(chatUrl,winName);

function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
createCookie('login','login',1);

}

someone can help here?

jscheuer1
06-13-2010, 03:10 AM
I reviving an old post because i needed some help on this matter.
I have installed prochatrooms in joomla . . .

What does the HTML code for your iframe look like? It should look something like so:


<iframe name="prochatrooms" src="about:blank" width="???" height="???"></iframe>

The highlighted portion is the most important. The ???'s should be set to your desired dimensions. The src is unimportant. Using "about:blank" provides an empty page prior to the user activating chat. If you have some default page you want in there prior to the user activating chat, use its address in place of "about:blank".

It's very possible none of this is the issue, but you have to have these things dealt with.

If you want more help:

Please post a link to a page on your site that contains the problematic code so we can check it out.

legolax
06-15-2010, 05:40 PM
Sry the late reply, i had some problems with my internet this weekend.

The iframe code that i set in the artichle is this:

{iframe}http://maquinasdeguerra.totalsfree.com/prochatrooms/index.php{/iframe}

I think the iframe work fine, but the auto login doesnt. u could chek my page here:

http://maquinasdeguerra.totalsfree.com

If u wanna make a login to try it, i have a register for testing:

username: teste
Password: casota

U will find two links in the top menu to acess the chat, the link named Chat Room is to open the page in full window and the link called Chat2 is suposed to open in the iframe inside the CMS page.

Ty for ur help

jscheuer1
06-16-2010, 11:27 AM
OK, the code you wrote in your post (post #12) in this thread is not the code of your chat.js file. Even if it were, that only gets executed when you click on the chat room button. Here is the code I found:


function launchChat()
{
var xOffSet = (screen.width - 225) / 2;
var yOffSet = (screen.height - 500) / 2;
var features = 'width=900,height=700,toolbar=0,directories=0,menubar=0,status=0,location=0,scrollbars=0,resizable=1';
var winName = 'prochatrooms';
var chatUrl = 'http://'+location.hostname+'/prochatrooms/index.php?uid='+userID+'&uname='+userName+'&room='+roomID;
window.location.replace(chatUrl);


function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
createCookie('login','login',1);

}

Now that works (not always) for the chat room in the same window. I say not always because the cookie is created after the window is replaced, so the cookie code may not always have a chance to execute in time. Once the window is replaced, all processing from the previous page stops.

If the code were what you have in post #12, it would still need to be run after the index.php?option=com_content&view=article&id=22&Itemid=81 page loads. And setting the cookie should be the first thing it does.

Using cookies to detect the login state isn't such a hot idea though. That information should already be in the session.

And, here is your iframe:


<iframe src="http://maquinasdeguerra.totalsfree.com/prochatrooms/index.php" marginheight="0" marginwidth="0" name="plg_iframe" width="100%" align="bottom" frameborder="0" height="400" scrolling="auto">No Frames</iframe>

Its name is plg_iframe. So even if you ran the code in post #12 onload of index.php?option=com_content&view=article&id=22&Itemid=81, it wouldn't do anything to the iframe. The code in post #12 is looking for an iframe by the name of prochatrooms.

If I were you, I wouldn't even be opening a new page. I'd have the iframe right on the main index page, but hidden. The function would reveal it, set the cookie and then open the chat page in it. The function would run when the user clicked the chat2 button. You can do it like you have it though.

To do it like you have it, the function needs to run onload of index.php?option=com_content&view=article&id=22&Itemid=81 and it needs to first set the cookie, and then open the page in the iframe by its name. You can keep the iframe name as it is, but should make its src attribute about:blank:


<iframe src="about:blank" marginheight="0" marginwidth="0" name="plg_iframe" width="100%" align="bottom" frameborder="0" height="400" scrolling="auto">No Frames</iframe>

This script should be on the index.php?option=com_content&view=article&id=22&Itemid=81 page:


function launchChat2()
{
function createCookie(name,value,days) {
if (days) {
var date = new Date();
date.setTime(date.getTime()+(days*24*60*60*1000));
var expires = "; expires="+date.toGMTString();
}
else var expires = "";
document.cookie = name+"="+value+expires+"; path=/";
}
createCookie('login','login',1);

var winName = 'plg_iframe';
var chatUrl = 'http://'+location.hostname+'/prochatrooms/index.php?uid='+userID+'&uname='+userName+'&room='+roomID;
myWin = window.open(chatUrl,winName);

}
if (window.addEventListener){
window.addEventListener('load', launchChat2, false);
}
else if (window.attachEvent){
window.attachEvent('onload', launchChat2);
}

There could still be other problems. But you have to tell the page to do what is needed to successfully open the chat in the iframe, otherwise nothing good will happen.

legolax
06-28-2010, 09:59 AM
jscheuer1 just want to thank you for ur help. Now it works perfectly.
I have replaced the code that u gave me in to the chat.js and the iframe in the index.php?option=com_content&view=article&id=22&Itemid=81 and the auto login in the chat is now working.
U r a genious. Once again thank you very much.

oziruz
01-26-2012, 03:38 AM
I am using the ProChatRooms Avatar Chat 3.0 and I am trying to get a URL formed to login . I want to be able to place a link on several areas for members of multiple sites to login directly something like www.mysite.com/index.php?username=myuser&password=mypass

any ideas? very very frustrated here