open link in new window and scroll original page to a certain position

Is it possible to open link in new window and scroll original page to a certain position at the same time ? Means that when the visitor closes the new window he is on a different place on the original page.
frijazzAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

deepaknetCommented:
You can have a new window open by window.open(). Scrolling is possible by window.scrollBy() It takes x and y coordinates.
0
jbondcCommented:
Hello frijazz,

This is more a javascript question...

If I understand your looking for a javascript function that will scroll to somewhere in your page.

I'd recommend using the scriptaculous library which you can download at: http://script.aculo.us/downloads

The following example would do the trick:

<script type="text/javascript" src="js/scriptaculous/lib/prototype.js"></script>
<script type="text/javascript" src="js/scriptaculous/src/scriptaculous.js"></script>

<a href='javascript:void(0);' onclick="new Effect.ScrollTo($('scroll_here'));  window.open ('http://www.experts-exchange.com','mywindow');">scroll then open popup</a>

content

<div id='scroll_here'>.........</div>
0
Cloud Class® Course: Microsoft Exchange Server

The MCTS: Microsoft Exchange Server 2010 certification validates your skills in supporting the maintenance and administration of the Exchange servers in an enterprise environment. Learn everything you need to know with this course.

C TGChief Software ArchitectCommented:
You can also use old html functionality for scrolling ...


You define an anchor in your page and on the link when you open the window you'll also scroll to the anchor. ;)


<a href="page.htm#jumphere" onclick="newPopup(myURL);">new Window</a>
...
<a name="jumphere"></a>
...


so when you click on the first link it opens the window and also scroll the page to the anchor (without to have to calculate the x/y position ... and also without loading javascript lybraries into client browser) ....

--
Hope I can Help,
TzH2O
http://romania.pentru-toti.ro

0
frijazzAuthor Commented:
thanks txh20, but with my limited knowledge, I cant get it to work.
What should I use <a name="jumphere"></a> for ?

I tried:
<a href="#" onclick="http://www.myothertestpage.com;">test</a>
and
<a href="#" onclick="newPopup(http://www.myothertestpage.com);">test</a>

It scrolls to the top, but no new window opens.
0
C TGChief Software ArchitectCommented:
Have you declared your newPopu function? ....

I'll give you a piece of example:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Popup Test</title>
<script language="javascript">
var popUpWin=0;

function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin', 'toolbar=no,location=no,directories=no,status=no,menubar=no,scrollbars=no,resizable=no,copyhistory=yes,width='+width+',height='+height+',left='+left+', top='+top+',screenX='+left+',screenY='+top+'');
}
</script>
</head>
<body>
<p><a href="#jumphere" onclick="popUpWindow('http://www.google.com', 20, 20, 400, 400)">here opens a popup, and scrolls to:</a> </p>
<p>...</p><p>...</p><p>...</p><p>...</p><p>...</p><p>...</p><p>...</p><p>...</p><p>...</p><p>...</p><p>...</p><p>...</p><p>...</p><p>...</p><p>...</p>
<p><a name="jumphere"></a>here</p>
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
</body>
</html>


Hope I can Help,
TzH2O
http://linkuri.pentru-toti.ro
0
frijazzAuthor Commented:
tzh20 thanks a lot, this is very good, much more than I need, but very good.
For the simplicity I need, I would have prefered your original suggestion with only html, but I didnt get it to work.
Please could you explain that one again ?

jbondc, thanks, I suppose your suggestion can do much of the same, but tzh20suggestion is simpler so I will give him the points.
deepaknet, thanks to you to, but I am going to inject this in thousands of files and dont see how i can use your suggestion.

I will give txh20 the points.


txh20, can you do this with onlu html ? This is how I want it:

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Popup Test</title>
<script language="javascript">
var popUpWin=0;

function popUpWindow(URLStr, left, top, width, height)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin');
}
</script>
</head>
<body>
<p>...</p><p>...</p><p>...</p><p>...</p><p>...</p><p>...</p><p>...
</p><p>...</p><p>...</p><p>...</p><p>...</p><p>...</p><p>...</p><p>...</p><p>...</p>
<p><a href="#" onclick="popUpWindow('http://www.google.com')">here opens a popup, and scrolls to:</a> </p>
<p>...</p><p>...</p><p>...</p><p>...</p><p>...</p><p>...</p><p>...</p><p>...</p><p>...</p>
<p>...</p><p>...</p><p>...</p><p>...</p><p>...</p><p>...</p>
<p><a name="jumphere"></a>here</p>
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
<br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br /><br />
</body>
</html>
0
C TGChief Software ArchitectCommented:
Ok. simpler than that :)

Here is the simpler way (as you said you want it): :)

<script language="javascript">
var popUpWin=0;
function popUpWindow(URLStr)
{
  if(popUpWin)
  {
    if(!popUpWin.closed) popUpWin.close();
  }
  popUpWin = open(URLStr, 'popUpWin');
}
</script>

and

<a href="#" onclick="popUpWindow('http://www.google.com')">

 using this popupFunction you will simply open a new browser (popup) with no customization.   Whit the function from the earlyer example you can customize your popup (size, toolbars, etc....) that's the difference.

Hope I can Help,
TzH2O
http://linkuri.pentru-toti.ro
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
frijazzAuthor Commented:
Thank you. The answer is very good. Sorry for my late acceptance.
I suppose that there are no way to achieve this by not putting
anything in the header ? I mean by putting all the code in the body.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Web Development

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.