<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> 
	<title>JavaScript Window Open Example</title> 

<SCRIPT language="JavaScript1.2"> 
function openwindow()


 <input type="button" value="Replace Me!" onClick=" window.location = 'http://www.google.com/' ; ">

<A href="javascript: openwindow()" >LINK 1</A> 
<P>Back to the article:<br> 
<a href="http://google.lk" target="_self">LINK 2</a> 

In this There are 2 links, in the 1st link, when we click on it, the web page will open in a new window. and when we right click on the link the (open link in new tab/window) popup doesn't appear.

In the 2nd link, when i click on it, it will open up in the same window, and also when i right click on it the popup that shows the (open link in new tab/window) popup appears.

So what i want to do is to edit the Javascript in the 1st link to have both functions;
1.) when a user click on the link, the web page should open in the same window
2.) when a user R- Click on the link, the popup should show up (open link in new tab/window).

Can some one please help me here, i'm lost :(

I dont think this will be possible. Whenever you right click on a link and try to open it in new tab/window it will open with the value set to the 'href' attribute

Try attaching this function to your link. Replace url with your url and name with whatever name you want.

var leftBtn;
var e = window.event;
leftBtn = 1; //IE detects left click differently
leftBtn = 0;
if(e.button===2){ //Right click
window.open(url, name)
}else if(e.button===leftBtn){ //Left click
window.location = url;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.