I am using the below code to open the page in a new window its working as expected but when I Right click "open in a new tab" its blocking with "about:blank#blocked", i am expecting the link to open in a new tab how to fix that?
<a href="javascript:;" style="color:red;" onclick="window.open('',null,'left=50,top=50,width=700,height=500,toolbar=1,location=0,resizable=1,scrollbars=1'); return false;">Limk</a>
I am using the below code to open the page in a new window its working as expected but when I Right click "open in a new tab" its blocking with "about:blank#blocked", i am expecting the link to open in a new tab how to fix that?
<a href="javascript:;" style="color:red;" onclick="window.open('http://www.la.unm.edu',null,'left=50,top=50,width=700,height=500,toolbar=1,location=0,resizable=1,scrollbars=1'); return false;">Limk</a>
Share
Improve this question
edited Aug 11, 2020 at 13:58
Lain
3,7261 gold badge21 silver badges27 bronze badges
asked Aug 11, 2020 at 13:52
jcrshankarjcrshankar
1,1969 gold badges27 silver badges51 bronze badges
3
-
1
Put the link in the
href
instead ofjavascript:;
. – Lain Commented Aug 11, 2020 at 14:00 - i tried by giving href="la.unm.edu" i have observed like, while closing the window its not going back to the main page from where the link got launched, rather its staying with the page(url) opened by open by window.open – jcrshankar Commented Aug 11, 2020 at 14:21
-
Had the same issue of
about:blank#blocked
. I had left out the closing</a>
tag. Adding this fixed the problem. – Gitau Harrison Commented Dec 30, 2021 at 14:23
3 Answers
Reset to default 4As stated by @Lain, just fill in the href
attribute.
<a href="http://www.la.unm.edu" style="color:red;" onclick="window.open('http://www.la.unm.edu',null,'left=50,top=50,width=700,height=500,toolbar=1,location=0,resizable=1,scrollbars=1'); return false;">Limk</a>
Working Sandbox Demo (adding this to code snippet, because code snippet doesn't allow clicking links offsite)
If you want to pletely control the context menu actions, so that "Open in a New Tab" behaves identically to window.open()
, then you should probably look at this answer: How to add a custom right-click menu to a webpage?.
Why are you getting about:blank#blocked
? Well, about:blank
is just a blank page, and when you right click an element, and click something in the context menu, that does not fire the onClick
event. So, it just shows a blank page.
Why does it say #blocked
, then, too? Probably because href contains "javascript", and the browser is trying to stop malicious code from executing. There are few resources explaining this, but AskLeo. says...
“about:blank#blocked” is sometimes displayed as the result of security software blocking access to something.
about:blank#blocked is thrown by browsers when a URL (as in the case of a canvas to image data-URL creation) is too long to be loaded as a standalone URL.
The data-URL limit lengths are about <2048 chars depending on the browser.
The solution for developers is a DataURL-to-BlobURL conversion.
The pseudo-code for the conversion would look something like this:
let U=URL.createObjectURL( DataURLtoBlob( Some_Data_Url) );
A.href=U; A.click(); // Your hidden anchor that opens the image in a tab
URL.revokeObjectURL(U); // remember to RELEASE the usually HUGE memory consumed by the blob.
<a href="javascript:;" style="color:red;" onclick="window.open('http://www.la.unm.edu',null,'left=50,top=50,width=700,height=500,toolbar=1,location=0,resizable=1,scrollbars=1'); return false;">Limk</a>