Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6179089
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T00:35:21+00:00 2026-05-24T00:35:21+00:00

I’m trying to learn some javascript and have gotten stuck. Right now, I have

  • 0

I’m trying to learn some javascript and have gotten stuck.

Right now, I have a really stupid simple gallery/image application. What I’m trying to do is make it so, when someone clicks an image, it hyperlinks them to a url I have in my model data all with ajax. The reason why is I’d like to also do something with ajax, like update a score/vote counter for the image when it is clicked.

Right now in the view I do this with:

<% @galleries.each do |g| %>
    <% for image in g.images %>
    <div id="picture">
      <%= render 'top_nav'%>

      <%= link_to image_tag(image.file_url(:preview)), g.source, :remote => true, :target => "_blank" %>

So far, with javascript I’ve figured out how to open a url, but only if I hardcode one into the javascript. Here’s my index.js.erb code (real simple):

window.open("http://www.google.com");

But I cannot figure out how I would link to my g.source like I am in my view’s do loop. How do I access this model data in javascript? I have figured out how to render this code on click of the image though, with the follow in …javascripts/application.js:

$(function() {
    $("#galleries #picture a img").live("click", function() {
        $.getScript(this.href);
        return false;
    });
});

Anyone have any pointers on how I can start interacting with my application’s data rather than hardcoding a url in the open?

Thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T00:35:21+00:00Added an answer on May 24, 2026 at 12:35 am

    You are pretty much on the right path to open image in a window, if the href you get from a points to image file.

    Try with this code:

    $(function() {
        $("#galleries #picture a img").live("click", function() {
            var lnk = $(this).closest("a").attr("href");
            window.open(lnk);
            return false;
        });
    });
    

    "#galleries #picture a img" is giving you img elements but you need the hyperlink which contains the image. so we will use $(this).closest("a") to get hyperlink for image url.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have just tried to save a simple *.rtf file with some websites and
this is what i have right now Drawing an RSS feed into the php,
I have a string like this: La Torre Eiffel paragonata all&#8217;Everest What PHP function
I am trying to render a haml file in a javascript response like so:
I am trying to loop through a bunch of documents I have to put
I am trying to understand how to use SyndicationItem to display feed which is
Basically, what I'm trying to create is a page of div tags, each has
link Im having trouble converting the html entites into html characters, (&# 8217;) i
For some reason, after submitting a string like this Jack’s Spindle from a text
I used javascript for loading a picture on my website depending on which small

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.