Viewing Avoid visitors try to open links in new tab/window (block control/command + click)

Avoid visitors try to open links in new tab/window (block control/command + click)



User: David P. 9 years ago
Hello all,

This is a demo of what I will have in my future website:

http://www.davidpratsjuan.com/TESTS/2iframes/java.html

As you can see, there are two iframes, one with the index and other with the content. When you click one link of the index page, the content in the iframe 2 shows the new page while the index page into the iframe 1 also changes highlighting what page are you viewing now.

So, it's necessary to avoid that visitors of the website try to open the links in new tabs or windows using secondary click of the mouse or just using control/command key + click. How can I avoid this?

Thank you very much!

Last edit 9 years ago
User: Roddy 9 years ago
You can remove the contextual menu on right or control click from individual links like this...

<a href="#" oncontextmenu="return false;">Link Text</a>

-------------------------------
Roddy

Website: http://everwebwidgets.com
Contact: http://everwebwidgets.com/ewWidgets-home/contact.html
NOTE: I am an EverWeb user and NOT affiliated with EverWeb! Any opinions expressed in this forum are my own.
User: David P. 9 years ago
Quote: Roddy - 17/05/2015 4:41:29
You can remove the contextual menu on right or control click from individual links like this...

<a href="#" oncontextmenu="return false;">Link Text</a>


Thanks! So easy, hehe. But visitors can continue using keyboard shortcuts like command + click on OS X to force the link to open in a new tab. Is there any solution to avoid this?
User: Roddy 9 years ago
I not sure why you would want to go to these lengths to upset your visitors. If they want to do all this stuff - let them!

-------------------------------
Roddy

Website: http://everwebwidgets.com
Contact: http://everwebwidgets.com/ewWidgets-home/contact.html
NOTE: I am an EverWeb user and NOT affiliated with EverWeb! Any opinions expressed in this forum are my own.
User: David P. 9 years ago
Quote: Roddy - 17/05/2015 5:27:48
I not sure why you would want to go to these lengths to upset your visitors. If they want to do all this stuff - let them!


Because trying to opening one of the links that are inside the frames in a new window or tab causes error pages, missing pages or it opens incompleted pages, because these are just part of frames.

I think to allow users to do this, gives them a bad feeling and denotes a careless and unprofessional design. So I want try to avoid this situations before they occur. Users will be able to open the main pages in new windows or in new tabs, of course, but not these that are only designed to be showed into frames.

Last edit 9 years ago
User: Jumbo T. 9 years ago
You already use this code when users open a page in a new window. But try at least to use the correct page :

<script type="text/java script">
if (window.location == window.parent.location)
this.window.location = 'java.html';
</script>

And it's java script, not Java.

Paste this in the Footer code box of the page you want tp preventright- click, drag and select :

<script>

var bodyLoad = document.getElementsByTagName("body")[0];
bodyLoad.setAttribute("oncontextmenu","return false;");
bodyLoad.setAttribute( "ondragstart","return false;");
bodyLoad.setAttribute("onselectstart","return false;");

</script>

Once is enough. Paste this code in the Header Code box of a page that uses an iframe

<script type="text/java script">
$(function(){
if (/iPhone|iPod|iPad/.test(navigator.userAgent))
$('iframe').wrap(function(){
var $this = $(this);
return $('<div />').css({
width: $this.attr('width'),
height: $this.attr('height'),
overflow: 'auto',
'-webkit-overflow-scrolling': 'touch'
});
});
})
</script>


Post Reply
You must login or signup to post.