Skip to content

dom createA('#', 'link') function doesn't work as expected #145

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
yining1023 opened this issue Oct 14, 2016 · 10 comments
Closed

dom createA('#', 'link') function doesn't work as expected #145

yining1023 opened this issue Oct 14, 2016 · 10 comments

Comments

@yining1023
Copy link
Member

yining1023 commented Oct 14, 2016

I tried to run the following sketch: http://alpha.editor.p5js.org/projects/rJ9PtlA0. It writes:

var a = createA('#', 'apples');

When user clicks on the link, it should do nothing. But in the editor, it will navigate the iframe to the whole web editor page, which totally makes sense. It's just an issue raised by running code in an iframe instead of the whole page. Maybe we could add something to prevent it from navigating away?

screen shot 2016-10-14 at 6 50 58 pm

@shiffman
Copy link
Member

@yining1023 it's working for me when I run the sketch, what specifically is not working for you?

@yining1023 yining1023 changed the title dom .parent() doesn't work well twice dom createA() function doesn't work as expected Oct 14, 2016
@yining1023 yining1023 changed the title dom createA() function doesn't work as expected dom createA('#', 'link') function doesn't work as expected Oct 14, 2016
@yining1023
Copy link
Member Author

@shiffman helped me to narrow down the problem. So I rephrased the issue above.

@catarak
Copy link
Member

catarak commented Oct 19, 2016

In the future what I want to do is render the iframe preview on a separate subdomain, for security reasons. I think it will fix this issue, but I'm not 100% sure.

@MichaelPaulukonis
Copy link

If you run the sketch in full - https://editor.p5js.org/full/rJ9PtlA0 - clicking on the link will instead provide:

{"message":"Asset does not exist"}

As it attempts to navigate to https://editor.p5js.org/full/rJ9PtlA0/#

I have found the same behavior when attempting to navigate to anchor links in other sketches.

Example here which uses anchor HTML from MDN


Expected behavior: clicking on link should cause page/sketch to navigate to anchor

Actual behavior: page/sketch disappears to be replaced with {"message":"Asset does not exist"}

@MichaelPaulukonis
Copy link

NOTE: Apparently, pre-pending about:srcdoc to the anchor links allows them to work.

So, instead of <a href="#foo">in-page link</a> you would have <a href="about:srcdoc#foo">in-page link</a>

Example here that works

Solution found on stackoverflow

@catarak
Copy link
Member

catarak commented Jan 13, 2020

oh, that's so awesome! the web editor could process all links that begin with a # and prepend them with about:srcdoc

@MichaelPaulukonis
Copy link

Sounds like that would work.

NOTE: it would have to be a prepend-on-render, or the links will not work when the sketch is downloaded, as the document is no longer about:srcdoc

@catarak
Copy link
Member

catarak commented Jan 28, 2020

Yes! There's some code in the web editor that doesn't get injected when a sketch is downloaded, which is

  • infinite loop protection
  • window console messaging
    So this code could be injected there!

@masakakinoki
Copy link

masakakinoki commented Nov 25, 2021

The about:srcdoc# solution is not working for me.

Expected behaviour: clicking on the 'blue berry' links only causes mousePressed function

Actual behaviour: clicking on the 'blue berry' links causes mousePressed function and then shows a blank preview

Example:
https://editor.p5js.org/abirdwhale/sketches/URhqrGUvZ

@masakakinoki
Copy link

Instead of about:srcdoc#, javascript:void(0) works for me.

@raclim raclim closed this as completed Jan 19, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants