?
Solved

Bringing target windows to front...

Posted on 2007-04-09
6
Medium Priority
?
241 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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
Secure Your WordPress Site: 5 Essential Approaches

WordPress is the web's most popular CMS, but its dominance also makes it a target for attackers. Our eBook will show you how to:

Prevent costly exploits of core and plugin vulnerabilities
Repel automated attacks
Lock down your dashboard, secure your code, and protect your users

 
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 1000 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

WordPress Tutorial 1: Installation & Setup

WordPress is a very popular option for running your web site and can be used to get your content online quickly for the world to see. This guide will walk you through installing the WordPress server software and the initial setup process.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Is your Office 365 signature not working the way you want it to? Are signature updates taking up too much of your time? Let's run through the most common problems that an IT administrator can encounter when dealing with Office 365 email signatures.
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
In this tutorial viewers will learn how to position overlapping items using z-index in CSS. They will also learn the restrictions on the z-index property.  Create a new HTML document with an internal stylesheet.: Create a div in CSS and name it Red.…
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…
Suggested Courses

770 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