Today is an interesting day. I was working on my project and found that i have a hard time looking for a way to disable my target attribute, _blank, which will open a new window and display the item there. Surprisingly, i found tons of how to create pop out box and many discussion regarding setting up a window.open instruction. But no one care to explain how to stop or disable it! Hence, i decide to write it out myself.
Pop out box
We all know how to enable a pop out box. We can do that either by window.open or using target attribute _blank to pass the work to another window. We can also do that for form submission but bringing out another box is not very professional unless you are showing certain information. Hence, most of us will go with ajax or iframe way of synchronize submission. Nonetheless, pop out box is a necessity in our web environment. While opening a new window box is easy but how about disabling it?
Disable _blank attribute
Disabling a pop out box or anything that will pop out is pretty simple. If you try to recall how you disable those anchor link, you might have an idea how you are going to disable all other types of link. Most pop out box is being initialize by a click. Hence, the event that we are interested with is onclick event handler. However, different people will have different ways of disabling an anchor link such as
But we are interested in
In order to disable pop out, it is the same as how we used to disable link. Hence, if you have a link such as this,
<a href="http://somewhere.com" target="_blank">link</a>
it will bring you to somewhere.com on a new pop out box. And if you want to prevent that, you will do this.
<a href="http://somewhere.com" target="_blank" onclick='return false;'>link</a>
That's it! To prevent window.open, we just remove that sentence! haha..