how to avoid about blank blocked while open a new tab
Asked Answered
C

3

6

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>
Camise answered 11/8, 2020 at 13:52 Comment(3)
Put the link in the href instead of javascript:;.Puisne
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.openCamise
Had the same issue of about:blank#blocked. I had left out the closing </a> tag. Adding this fixed the problem.Theorbo
M
4

As 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 completely 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.com says...

“about:blank#blocked” is sometimes displayed as the result of security software blocking access to something.

Maryannamaryanne answered 11/8, 2020 at 14:6 Comment(4)
thanks for answering yes i understand that, before posting the question 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.openCamise
@jcrshankar: Okay, I think I understand now -- you want "open in new window" to behave exactly like window.open. In that case, you need to override the context menu, and make a custom one, so you can control the events of clicking on the context menu. Something like this: How to add a custom right-click menu to a webpage? Does that work? I can update my answer with mentioning that, if that's correct.Maryannamaryanne
hi, on PageA i have an Link. when i click on the link the new page(say PageB) should get load on new window using(window.open) when i am closing the window it should back to PageA again. similarly when i right click and selecting "open a new tab" on the link from PageA it should get load the PageB on a new tab.Camise
@jcrshankar: Hi, thanks for getting back to me. The code above seems to do exactly as you describe. I tested with a working demo. Click the link: Window pops up, close window, I'm back at the browser and the homepage. Right-click link, click open in new-tab, close new tab, I'm back at the browser and the homepage.Maryannamaryanne
S
3

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.
Sulphurbottom answered 21/3, 2023 at 4:15 Comment(0)
S
-1

<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>
Soapbox answered 13/10 at 19:39 Comment(1)
Your answer could be improved with additional supporting information. Please edit to add further details, such as citations or documentation, so that others can confirm that your answer is correct. You can find more information on how to write good answers in the help center.Chronology

© 2022 - 2024 — McMap. All rights reserved.