Open Bug 911746 Opened 11 years ago Updated 2 years ago

special-case javascript: URLs that return undefined if link target is _blank

Categories

(Core :: DOM: Core & HTML, defect, P5)

defect

Tracking

()

People

(Reporter: hsteen, Unassigned)

References

Details

(Keywords: dev-doc-needed)

Attachments

(1 file)

Spun off from bug 790893: some pages break due to constructs like <a href="javascript:doFoo()" target="_blank"> or javascript: links in a page that has BASE target=_blank. It is nevertheless considered proper and important to support target=_blank for javascript: links that generate HTML.

The best solution may be to only respect target=_blank for javascript: links if they actually generate some output.

(By memory, Opera changed to doing this for shift-clicking javascript: links a long time ago, and probably handled target=_blank as a side effect of this)
Blocks: 790893
Blocks: 911150
OS: Linux → All
Hardware: x86 → All
Olli, what do you think?  There's some compat risk here, but hopefully not too much...
Attachment #802030 - Flags: review?(bugs)
Assignee: nobody → bzbarsky
Status: NEW → ASSIGNED
The particular compat worry is:

  <a onclick="window.open('javascript:')">Click me</a>

and expecting that window to stick around.  We don't really have a way to tell that case apart from the

  <a href="javascript:" target="_blank">Click me</a>

case...
Whiteboard: [need review]
So what do other browser do in that case?
<a onclick="window.open('javascript:')">Click me</a> looks pretty important to not break.
> So what do other browser do in that case?

Open a window.
What I could do is restrict the auto-closing behavior to cases when the script is nonempty.  That would keep 'javascript:' working as now.  Feeld hacky.
Oh, I think I misunderstood. I thought any onclick="window.open('javascript: ....')".
When window.open is called, someone clearly wants to open a new window.
And even if value isn't returned, javascript: url may generate content by accessing document.body.innerHTML for example.
> I thought any onclick="window.open('javascript: ....')".

That's basically what the current patch does, yes....
Comment on attachment 802030 [details] [diff] [review]
If a javascript: load had no return value and was being opened in a new window, close the new window, since it's not actually needed for anything.

So I'm not really ok with this. window.open is window.open
Attachment #802030 - Flags: review?(bugs) → review-
OK, but target=_blank is semantically equivalent to window.open.  Sounds like we should wontfix this bug, then....
Assignee: bzbarsky → nobody
Whiteboard: [need review]
I agree that window.open('javascript:..') needs to work. It would be nice if the <a href="javascript:..." target="_blank"> case could be detected at an earlier stage so that we could prevent opening the window rather than auto-closing it (and make it target=_blank only, not window.open()). If that's not possible I guess we have to wontfix :-/
Keywords: dev-doc-needed
last site found to assume this will be ignored: Google Maps. See dup. :-/

Simple proof:
for(var i=0; i<document.links.length; i++)if(document.links[i].target && /javascript:/.test(document.links[i].href))document.links[i].target=''
makes the problem go away.
https://bugzilla.mozilla.org/show_bug.cgi?id=1472046

Move all DOM bugs that haven’t been updated in more than 3 years and has no one currently assigned to P5.

If you have questions, please contact :mdaly.
Priority: -- → P5
No assignee, updating the status.
Status: ASSIGNED → NEW
No assignee, updating the status.
No assignee, updating the status.
No assignee, updating the status.
No assignee, updating the status.
Component: DOM → DOM: Core & HTML
Severity: normal → S3
You need to log in before you can comment on or make changes to this bug.

Attachment

General

Created:
Updated:
Size: