Solved

Bringing target windows to front...

Posted on 2007-04-09
6
233 Views
Last Modified: 2010-04-09
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  

0
Comment
Question by:plovfure
  • 3
  • 2
6 Comments
 
LVL 10

Expert Comment

by:Jaax
ID: 18874841
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>
0
 

Author Comment

by:plovfure
ID: 18874948
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
0
 

Author Comment

by:plovfure
ID: 18874950
And thanks for your help by the way
0
What Is Threat Intelligence?

Threat intelligence is often discussed, but rarely understood. Starting with a precise definition, along with clear business goals, is essential.

 
LVL 10

Expert Comment

by:Jaax
ID: 18874971
onlick="openWindow('http://www.yahoo.com')">
Note that the url is embedded within a single quote. Hope you didn't miss it.
0
 
LVL 10

Accepted Solution

by:
Jaax earned 250 total points
ID: 18874994
Sorry! there was a typo error and also the anchor needs to be placed within the body tag.
Also made some minor changes. This code does work :

<html>
<head>
      <script>
      function openWindow(url){
         winHan = window.open (url, "othertarget");
         if(winHan){
               winHan.focus();
         }
      }

      </script>
</head>

<body>
      <a href="#" onclick="openWindow('http://www.yahoo.com'); return false"> Click Here</a>
</body>
</html>
0
 
LVL 4

Expert Comment

by:cheesygit182
ID: 18875226
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
0

Featured Post

Highfive Gives IT Their Time Back

Highfive is so simple that setting up every meeting room takes just minutes and every employee will be able to start or join a call from any room with ease. Never be called into a meeting just to get it started again. This is how video conferencing should work!

Join & Write a Comment

Suggested Solutions

Title # Comments Views Activity
Align a <div> to a table row 3 38
html select on change 3 25
jquery adding parameter to hyperlink url 8 35
C3-->D3 Line Chart 4 17
Have you tried to learn about Unicode, UTF-8, and multibyte text encoding and all the articles are just too "academic" or too technical? This article aims to make the whole topic easy for just about anyone to understand.
This is a PowerShell web interface I use to manage some task as a network administrator. Clicking an action button on the left frame will display a form in the middle frame to input some data in textboxes, process this data in PowerShell and display…
In this tutorial viewers will learn how add a full-size background image to a webpage using CSS3. Create a new HTML document with an internal stylesheet.: In CSS, define the html element to have a background image. Use a high resolution image.: In t…
The viewer will learn the benefit of using external CSS files and the relationship between class and ID selectors. Create your external css file by saving it as style.css then set up your style tags: (CODE) Reference the nav tag and set your prop…

707 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now