Jump to content

Can't Open URL in New Tab


Recommended Posts

I am new to website development. I can't figure out how to open a new tab for the following javasript. I went through related questions but nothing worked for me. I want the browser to open a new tab when someone clicks on the link (example.com) below. The code target="_blank doesn't work here... What code should I add and where should I place that code?

My html code is here -
<section id="work-grid" class="site-inner">
<div class="work-item" data-groups='["all", "webdesign"]' data-url="http://example.com">
<figure class="image-container"><img src="images/work/web-one.jpg" /></figure>
Thanks in advance.
Link to comment
Share on other sites

This jQuery will probably work, but only on browsers that don't block popups. There is no guarantee any link with _blank will open a new tab. It depends on the individual users browser settings.

$('div.work-item').on('click', function() {
  window.open($(this).data('url'), '_blank');
Link to comment
Share on other sites

  • 2 weeks later...

i agree with cronix. mostly. rather than wrapping the img in an anchor tag, might work better to just style the anchor with background image. would replace the div with an <a></a>

something like:

<a href="http://example.com" id="example_link"></a>


#example_link {
    width:[width of image];
    height:[height of image];
Link to comment
Share on other sites

Personally I think that using css is probably going to be your best bet in this situation.. until I can see your java script at least.


You can then link simply by doing something as easy as.

<a href="#" id="69"></a>

If you're unaware of what this is doing it's basically doing the same thing that including a straight image would do.

<a href="#"><img src="#"/></a>

Going to keep an eye on this thread in hopes of the Java being posted because this method will get annoying very quickly.

Link to comment
Share on other sites

  • 2 months later...
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.