PDA

View Full Version : right click



Mike4x4
05-11-2008, 05:00 AM
Hi people, could i havew a base code so if i left or right mouse click inside a cell it pops up a webpage?

jscheuer1
05-11-2008, 04:05 PM
This will often be blocked (security and usability settings in modern browsers), especially for the right click, but here it is:


<td onclick="window.open('some.htm','_blank');">
Whatever
</td>


You will probably have slightly more compliance in browsers if you do it like so:


<td>
<a href="some.htm" onclick="window.open(this.href,'_blank');return false;"
style="display:block;width:100%;height:100%;">Whatever</a>
</td>

matthewbluewars
05-11-2008, 08:02 PM
This will often be blocked (security and usability settings in modern browsers), especially for the right click, but here it is:


<td onclick="window.open('some.htm','_blank');">
Whatever
</td>


You will probably have slightly more compliance in browsers if you do it like so:


<td>
<a href="some.htm" onclick="window.open(this.href,'_blank');return false;"
style="display:block;width:100%;height:100%;">Whatever</a>
</td>

You could just use <a href="..." style="..." target="_blank">...</a> instead of
<a href="..." onclick="window.open(this.href,'_blank');return false;"
style="...">...</a>. Plus, it is reccommended that you don't use events in attributes such as <button onclick="...">...</button>.

jscheuer1
05-11-2008, 10:37 PM
You could just use <a href="..." style="..." target="_blank">...</a> instead of
<a href="..." onclick="window.open(this.href,'_blank');return false;"
style="...">...</a>. Plus, it is reccommended that you don't use events in attributes such as <button onclick="...">...</button>.


Hmm, I'm not too big on what is 'recommended' without an explanation as to why it is recommended.

Regardless of whether it's done my way or your way, I don't recommend doing this at all (due to its often being blocked in the manner I already outlined in my first post in this thread).

Unless it isn't all that important that it happen -in other words the site would work fine if the page opens in the same window/tab, another window/tab, or not at all - all possibilities for any given user with any attempt like this. I would also note that your use of the target attribute is deprecated (meaning that future support is questionable), so at lest in that sense is not recommended.