Notices
Computer & Technology Related Post here for help and discussion of computing and related technology. Internet, TVs, phones, consoles, computers, tablets and any other gadgets.

Need a bit of help in HTML/javascript

Thread Tools
 
Search this Thread
 
Old 01 September 2002, 10:26 PM
  #1  
WRX.
Scooby Newbie
Thread Starter
 
WRX.'s Avatar
 
Join Date: Dec 2001
Posts: 15
Likes: 0
Received 0 Likes on 0 Posts
Question

Hi,
I am building a webpage and on it I want to have links on it so when they are clicked on a small popup window opens. I am using the following code which works fine but with one small problem. When the first link is clicked on it opens up correctly in front of the window the page is in, however when another link is clicked on, the popup window opens in the same window as first time but stays behind the main window. How can I change it so the popup window always opens in front of the main window. Here is the code I'm using

<script language="javascript">

function ADpop(url)
{
var win = window.open(url, 'ADpop',"width=250,height=100,top=50, left=150,status=0,toolbar=0,menubar=0,location=0,r esizeable=1,scrollbars=yes");
win.focus();
}


</script>

That bit goes in the head of the page code and the following around the link:

<a href="Javascript:ADpop(popup.html');">Popup Window Here</a>

Any ideas,
Thanks in advance
Old 02 September 2002, 12:04 AM
  #2  
AndrewW
Scooby Regular
 
AndrewW's Avatar
 
Join Date: Nov 2000
Location: Brisbane, Oz
Posts: 704
Likes: 0
Received 0 Likes on 0 Posts
Post

<SCRIPT LANGUAGE="JavaScript"><!--
function openMyWindow() {
windowName = window.open('blah.htm');
}
//--></SCRIPT>

<SCRIPT LANGUAGE="JavaScript1.1"><!--
function openMyWindow() {
windowName = window.open('blah.htm');
windowName.focus();
}
//--></SCRIPT>



The extra code is needed because this functionality is only provided by javvascript 1.1

Also, a very good discussion of creating modal windows in javascript can be found at http://developer.netscape.com/viewso...man_modal.html

Andrew.
Old 02 September 2002, 12:11 AM
  #3  
IWatkins
Scooby Regular
 
IWatkins's Avatar
 
Join Date: Mar 2000
Location: Gloucestershire, home of the lawnmower.
Posts: 4,531
Likes: 0
Received 0 Likes on 0 Posts
Post

I'm not sure (I don't do Javascript) but I'm guessing that because you have named the popup window 'ADpop', that if it is already open, clicking the link again will only refresh the currently opened window.

I.e. you click the link. The main window looses focus as the popup window appears in front. If you then click the link on the main window again while the popup is still open, the popup gets forced backwards as you click the link, but as a new window isn't being created it is simply refreshed with the page content but not pulled forwards to be refocused even though you use win.focus(). Maybe win.focus only brings the whole browser into focus, not necessarily the currently selected window..... or something.

I would suggest that you actually force the focus by using the name of the popup window. Not sure how you do that, but maybe something like:

<a href="Javascript:ADpop(popup.html');win.ADpop.focu s();">Popup Window Here</a>

or whatever the syntax is to target an action on a named window.

Best I can do.

Cheers

Ian
Old 02 September 2002, 12:11 AM
  #4  
IWatkins
Scooby Regular
 
IWatkins's Avatar
 
Join Date: Mar 2000
Location: Gloucestershire, home of the lawnmower.
Posts: 4,531
Likes: 0
Received 0 Likes on 0 Posts
Post

Damn, someone got in there before me with the answer
Old 02 September 2002, 12:20 AM
  #5  
AndrewW
Scooby Regular
 
AndrewW's Avatar
 
Join Date: Nov 2000
Location: Brisbane, Oz
Posts: 704
Likes: 0
Received 0 Likes on 0 Posts
Post

Old 02 September 2002, 01:04 AM
  #6  
WRX.
Scooby Newbie
Thread Starter
 
WRX.'s Avatar
 
Join Date: Dec 2001
Posts: 15
Likes: 0
Received 0 Likes on 0 Posts
Post

Hi Andrew and Ian,
Thanks for the replies, I still haven't worked it out though.

Andrew: Where do I put that code, in the head section? and on which page, the one with the link or the page that pops up in the small window.

Thanks again
Old 02 September 2002, 02:07 AM
  #7  
legacyPete
Scooby Regular
 
legacyPete's Avatar
 
Join Date: Dec 2001
Posts: 202
Likes: 0
Received 0 Likes on 0 Posts
Post

I had the same problem a while ago, try this:

<script language="javascript">
<!--
var win;
function ADpop(url) {
win = window.open(url, 'ADpop',"width=250,height=100,top=50, left=150,status=0,toolbar=0,menubar=0,location=0,r esizeable=1,scrollbars=yes");
win.focus();
win = null;
}
//-->
</script>
Old 02 September 2002, 06:27 AM
  #8  
AndrewW
Scooby Regular
 
AndrewW's Avatar
 
Join Date: Nov 2000
Location: Brisbane, Oz
Posts: 704
Likes: 0
Received 0 Likes on 0 Posts
Post

Hi,

That'll teach me to read your code properly

You are already doing what I have suggested, in that you are using the win.focus function to bring the window to the front.

My only thought is that you might be using a web browser that does not support javascript 1.1, and hence the focus() call is not working.

Sorry I can't be more help.

Andrew.
Old 02 September 2002, 07:05 PM
  #9  
WRX.
Scooby Newbie
Thread Starter
 
WRX.'s Avatar
 
Join Date: Dec 2001
Posts: 15
Likes: 0
Received 0 Likes on 0 Posts
Post

Hi Guys,
Still not working right, thanks for your help anyway.

Andrew: I'm using IE5 so I doubt thats the problem.

I'll try do some searchs for a suiatable code.

Thanks
Old 02 September 2002, 07:19 PM
  #10  
GaryK
Scooby Regular
 
GaryK's Avatar
 
Join Date: Sep 1999
Location: Bedfordshire
Posts: 4,037
Likes: 0
Received 0 Likes on 0 Posts
Post

WRX,

Andrew maybe right, just done a system - ASP / Javascript, we had an error message appearing when trying to dynamically set focus to a form object on test machines but not on our dev. machines, turned out the problem was with the version of IE, on 5.5 it worked fine on 5.0 it did not, just a thought.

Gary
Related Topics
Thread
Thread Starter
Forum
Replies
Last Post
JimBowen
ICE
5
02 July 2023 01:54 PM
KAS35RSTI
Subaru
27
04 November 2021 07:12 PM
Frizzle-Dee
Essex Subaru Owners Club
13
01 December 2015 09:37 AM
slimwiltaz
General Technical
20
09 October 2015 07:40 PM
Benrowe727
ScoobyNet General
7
28 September 2015 07:05 AM



Quick Reply: Need a bit of help in HTML/javascript



All times are GMT +1. The time now is 07:17 AM.