Log in

View Full Version : One click to two links, how ???



i777
08-19-2006, 05:41 PM
Example:
I have a image and two links:
Firt link: http://www.google.com
Second link: http://www.yahoo.com
I want only a click to image for go to the fist link (open same window) and open the second link in a new window.
How do this work? Everybody can help? :confused:

mburt
08-19-2006, 05:54 PM
Change the target of the link to "_blank"

Look here:

<a href="http://www.yahoo.com" target="_blank">Yahoo</a>

i777
08-19-2006, 06:15 PM
Change the target of the link to "_blank"

Look here:

<a href="http://www.yahoo.com" target="_blank">Yahoo</a>

Thanks for your help, but you didn't understand my idea.


I want only a click to image for go to the fist link (open same window) and open the second link in a new window.

shachi
08-19-2006, 06:17 PM
see this: http://www.huntingground.freeserve.co.uk/scripts/dualbutt.htm

DimX
08-19-2006, 06:26 PM
The easiest way: (not sure about browser compatibility)


<a href="javascript:void(document.getElementById("link1").click()); void(document.getElementById("link2").click())"><img src="..." alt="..." /></a>
<a id="link1" href="http://www.google.com">Link 1</a>
<a id="link2" href="http://www.yahoo.com" target="_blank">Link 2</a>

mburt
08-19-2006, 06:32 PM
click() doesn't work for FF as I'm aware of.

i777
08-19-2006, 06:37 PM
see this: http://www.huntingground.freeserve.co.uk/scripts/dualbutt.htm


The following script allows one button to have two or more functions
On the first press function one is run, on the second press function two is run.
To show how this works I have used an alert box as function one and two.

Thank you, but only a click - one press, not two.


click() doesn't work for FF as I'm aware of.

I has just tested, it's right.

Anyone, please!

DimX
08-19-2006, 06:44 PM
click() doesn't work for FF as I'm aware of.
Yeah, that's true. :rolleyes:

But this should work:


<script type="text/javascript">
function openOtherLinks(id1, id2) {
var link1 = document.getElementById(id1);
var link2 = document.getElementById(id2);
if(!link1.href || !link2.href)
return;
window.open(link2.href);
document.location.replace(link1.href);
}
</script>



<a href="javascript:openOtherLinks('link1', 'link2')"><img src="..." alt="..." /></a>
<a id="link1" href="http://www.google.com">Link 1</a>
<a id="link2" href="http://www.yahoo.com" target="_blank">Link 2</a>

i777
08-19-2006, 06:57 PM
Yeah, It works. Thanks a lot :)

But, I can't use BACK button for return to the page include image after go to the firt link (google.com).

Can you fix this error ???

i777
08-20-2006, 05:58 AM
Can anyone help me, please!

DimX
08-20-2006, 08:59 AM
Hmm, that's because of the replace() functon.
Well then use this code:


<script type="text/javascript">
function openOtherLinks(id1, id2) {
var link1 = document.getElementById(id1);
var link2 = document.getElementById(id2);
if(!link1.href || !link2.href)
return;
window.open(link2.href);
document.location = link1.href;
}
</script>

jscheuer1
08-20-2006, 09:44 AM
<a href="http://www.google.com" onclick="window.open('http://www.yahoo.com');return true;">Google here, Yahoo in a new window</a>

i777
08-21-2006, 04:42 AM
Oh, It works very well. Thank a lot. (^_^)

romperstomper
09-20-2007, 07:15 PM
<a href="http://www.google.com" onclick="window.open('http://www.yahoo.com');return true;">Google here, Yahoo in a new window</a>

Indeed very nice, but I have also a question. We shall use the yahoo/google example here.

When you click this link, you open google in your parent window, and yahoo in a new window. Exactely what I want, only I don't want to go to the new window, but I want to stay in my parent window. (Now the opposites happens)

So, is there anyone who can help me out?

boogyman
09-20-2007, 07:53 PM
you want both of them to load in the parent window?

romperstomper
09-21-2007, 02:36 AM
No, you're getting me wrong, when I click the links, one opens in the main, and the other opens in the new window. so far so good.

But I want the same as 'the-middle-mouse-button-in-Firefox'. That you don't go (as website viewer) to the new window, but you stay watching in the parent window.

romperstomper
09-21-2007, 03:10 AM
Waht I meant was that the link in window.open must open in a background tab. So now my question is, How do i do this?

jscheuer1
09-21-2007, 05:48 AM
In theory, this should work:


<a href="http://www.google.com" onclick="window.open('http://www.yahoo.com');self.focus();return true;">Google here, Yahoo in a new window</a>


However, in testing this appears to only work in Opera. If you own both of the new pages being loaded, you can put this on the page being loaded into the original window:


<script type="text/javascript">
onload=function(){self.focus();};
</script>

and this on the page being loaded into the new window:


<script type="text/javascript">
onload=function(){self.blur();};
</script>

romperstomper
09-21-2007, 12:51 PM
In theory, this should work:


<a href="http://www.google.com" onclick="window.open('http://www.yahoo.com');self.focus();return true;">Google here, Yahoo in a new window</a>


However, in testing this appears to only work in Opera. If you own both of the new pages being loaded, you can put this on the page being loaded into the original window:


<script type="text/javascript">
onload=function(){self.focus();};
</script>

and this on the page being loaded into the new window:


<script type="text/javascript">
onload=function(){self.blur();};
</script>

Doesn't work in Firefox and IE, and I own only the page that opens in the parent window, the window that opens in window.open is not mine.

Anyone who has another solution?

jscheuer1
09-21-2007, 03:11 PM
If you own both of the new pages being loaded
Doesn't work in Firefox and IE, and I own only the page that opens in the parent window, the window that opens in window.open is not mine.


Well the page in the pop up window is the crucial one. Don't say that it doesn't work though, if you haven't been able to follow the directions.

A timeout could be set on the parent window's new page to focus it after the external page loaded, but it would become a matter of guessing how much time the external page takes to load. This of course would vary widely depending upon bandwidth. If the external page can be en-framed in an iframe, the onload event of the iframe containing it on a page that you do own could probably be used, but that gets complicated, both from a scripting and a layout perspective.

romperstomper
09-24-2007, 01:30 PM
Solved the problem myself :

you place this in your <head> section (we're using the Google/Yahoo example):

<SCRIPT LANGUAGE="JavaScript">

function goNewWin() {

TheNewWin =window.open("http://www.yahoo.com",'TheNewpop','toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1');

TheNewWin.blur();

}
</SCRIPT>


and you use this to place a link :

<a href="http://www.google.com" onClick="goNewWin();self.focus();">Google</a>

boogyman
09-24-2007, 01:40 PM
<SCRIPT LANGUAGE="JavaScript">
you shouldn't be using language anymore.

<script type="text/javascript">


TheNewWin.blur();
why are you blurring the new window? you want it to open, so you should be using focus

TheNewWin.focus();

jscheuer1
09-24-2007, 03:08 PM
Solved the problem myself :

you place this in your <head> section (we're using the Google/Yahoo example):

<SCRIPT LANGUAGE="JavaScript">

function goNewWin() {

TheNewWin =window.open("http://www.yahoo.com",'TheNewpop','toolbar=1,location=1,directories=1,status=1,menubar=1,scrollbars=1,resizable=1');

TheNewWin.blur();

}
</SCRIPT>


and you use this to place a link :

<a href="http://www.google.com" onClick="goNewWin();self.focus();">Google</a>

Still won't work in IE 7, but now works in Opera (which worked with simpler code) and FF (which did not).


you shouldn't be using language anymore.

<script type="text/javascript">


why are you blurring the new window? you want it to open, so you should be using focus

TheNewWin.focus();

You are correct about the language attribute, it has been replaced by the type attribute. However, you are wrong about focus/blur, only because it is romperstomper's aim to open the new window in the background.