Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
?
Solved

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

Posted on 2006-04-25
9
Medium Priority
?
429 Views
Last Modified: 2011-10-03
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.
0
Comment
Question by:frijazz
  • 3
  • 3
  • 2
  • +1
9 Comments
 
LVL 15

Expert Comment

by:deepaknet
ID: 16534918
You can have a new window open by window.open(). Scrolling is possible by window.scrollBy() It takes x and y coordinates.
0
 
LVL 4

Expert Comment

by:jbondc
ID: 16534966
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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
LVL 7

Expert Comment

by:C TG
ID: 16536990
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
 

Author Comment

by:frijazz
ID: 16576177
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
 
LVL 7

Expert Comment

by:C TG
ID: 16583857
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
 

Author Comment

by:frijazz
ID: 16589761
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
 
LVL 7

Accepted Solution

by:
C TG earned 800 total points
ID: 16595392
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
 

Author Comment

by:frijazz
ID: 16653571
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

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Question has a verified solution.

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

Without even knowing it, most of us are using web applications on a daily basis.  In fact, Gmail and Yahoo email, Twitter, Facebook, and eBay are used by most of us daily—and they are web applications. We generally confuse these web applications to…
The first step to building an amazing About page is to figure out what you want the page to say about your company. You then must grab the attention of the reader, boast a bit, tell a story and let others brag about you. With a little bit of thought…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to create and use a small PHP class to apply a watermark to an image. This video shows the viewer the setup for the PHP watermark as well as important coding language. Continue to Part 2 to learn the core code used in creat…
Suggested Courses
Course of the Month13 days, 21 hours left to enroll

580 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