preview app feature to open link in same tab
i have three cards when i hover on them top div shows image of that card but when i click on it it opens the url assigned to it in new tab.
BUT
i have a new idea when i tap on it, it should open url assigned to it like "preview" just like macos does when we use spacebar to preview, so the link won't open in new tab.
i hope i was able to explain this properly.
10 Replies
You could achieve this by loading the content into a dialog or modal (basically the same thing).
Take a look at this:
https://developer.mozilla.org/en-US/docs/Web/HTML/Element/dialog
MDN Web Docs
: The Dialog element - HTML: HyperText Markup Language | MDN
The HTML element represents a modal or non-modal dialog box or other interactive component, such as a dismissible alert, inspector, or subwindow.
You can either load the content into the "dialog" via JS or, probably simpler in your case, already have it within the dialog element on page load.
looks like it will take lot of time so i'ma keep it on side for a while
Not really, certainly less time than creating a whole new page for each section.
Obviously it depends on what you actually want to show in these "preview" windows.
A dialog can be created something like this:
By default it will open in the center of the viewport (depending on any CSS resets that you may have) and it can be styled just like any other element.
i just want it to open url in it
like you know
<a href="google.html">
take a look at this https://codepen.io/kev00690/pen/wvVVqmB
chat gpt made it and i improved it
by css haha
In that code you are loading the external url into an iframe which is then being displayed within a "modal" window.
"manually" creating the modal window was the way this was done before the <dialog> element was added to HTML.
The same thing can be achieved with a <dialog>
Very similar so it is up to you.
One thing I will say though is that you shouldn't be attaching the eventListener to <div> or <span>.
These should be buttons or, some might say that in this case they could be <a> elements (as technically they are opening an external URL).
hey i was out man couldn't reply sorry bout that
i understand it but then i thought it will be more useful if i use it for some smaller effects.
not for bigger links