Link to home
Start Free TrialLog in
Avatar of plovfure
plovfure

asked on

Bringing target windows to front...

I have decided to try to teach myself some basic html through a project I can use rather than through abstrat "hello world" examples. The idea of my newest project is to have an small "control panel" windows with my favourite links. This part is easy. Basically it is all a matter of the name of the window to be controlled. So, pressing the link

<a href="http://www.yahoo.dk" target="otherwindow">Click Here</a>
in one window will cause yahoo to open in a new window (unless the window named "otherwindow" is already opened; then it will just change the contents of it). Now, the trouble is that it is only when a new window is opened from the "controller window", it is set to be active. When you change the content by pressing another link (or the same link for that matter) the controller window stays in the front, whereas the controlled window stays in the back.

What I am after is - in other words - a way to change the content in the controlled window and, at the same time force the controlled window to the front.

Help will be appreciated!

plovfure  

Avatar of Jaax
Jaax
Flag of India image

Instead of opening the page from href, open it from a function called from hyperlink

<a href="#" onlick="openWindow(http://'www.yahoo.com')"> Click Here</a>

In your script tag define a function
<scriipt>
function openWindow(url){
   winHan = window.open(url, "othertarget");
   if(winHan){
       winHan.focus();
   }
}

</script>
Avatar of plovfure
plovfure

ASKER

Thanks, but I am not completely sure that I got it right.  This is my small "control panel":
<html>
<head>
<script>
function openWindow(url){
   winHan = window.open (url, "othertarget");
   if(winHan){
       winHan.focus();
   }
}

</script>

</head>
<a href="#" onlick="openWindow(http://www.yahoo.com)"> Click Here</a>
</html>

I do not exactly understand the workings of the script, but I reckon that what it does is to proces the webaddress after the openwindow () to open it in the target window called "othertarget". But the above code does mot work for me. I also tried to have the script outside the head, but in both instances nothing happens.

Thanks, LP
And thanks for your help by the way
onlick="openWindow('http://www.yahoo.com')">
Note that the url is embedded within a single quote. Hope you didn't miss it.
ASKER CERTIFIED SOLUTION
Avatar of Jaax
Jaax
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Hi, try this:

<html>
<head>

<script language="javascript" type="text/javascript">
<!--
function popupandfocus(url){
newwindow = window.open (url,'name');// create a new window(popup) stored in a variable called "newwindow"
if (window.focus) {newwindow.focus()}// if the browser supports focusing popups, give the "newwindow" focus(bring it to front)
return false;// stops the "control window" from changing it's url to "controlwindow.html#". check it out here: http://cs.wellesley.edu/~cs110/examples/return.html
}
// -->
</script>

</head>
<body>
Click <a href="http://www.yahoo.com" target="_blank">Here</a> to open a normal popup window with yahoo.com inside, using plain old html.<br>
Click <a href="http://www.yahoo.com" onclick="return popupandfocus('http://www.yahoo.com')">Here</a> to open a popup window with yahoo.com inside, and focus it, using javascript.<br>
Click <a href="http://www.google.com" onclick="return popupandfocus('http://www.google.com')">Here</a> to change the content of the popup window to google.com, and focus it, using javascript.<br>
</body>
</html>

If you would like to know more about how it works, just ask.

~cheesygit182