I have a webpage that has a list of anchors on it which use clearbox3 to display them as a gallery. Only the first anchor has a textual link to click "View Photos (3)". The others are just to get the images into the clearbox gallery. And that works fine. What I need is a way to bring up the clearbox image gallery from the user click of another control. I'm currenting trying to do it from an asp.net ImageButton control (maps to input tag), but have also tried to just use an anchor too without luck.
The anchors for the clearbox image gallery look like this:
<a id="photoLink" href="http://tempo5.sandicor.com/SNDImages/221/071064797_101_12.jpg" rel="clearbox[gallery=929 Border Ave, Del Mar, California, 92014,,tnhrf=http://tempo5.sandicor.com/SNDImages/221/071064797_101_12.jpg]">View Photos (6)</a>
My "other" control (currently an asp.net ImageButton --> maps to a an input control looks like this:
<input type="image" name="ctl00$ContentPlaceHolderCol2$mainPropertyPhoto" id="ctl00_ContentPlaceHolderCol2_mainPropertyPhoto" src="http://tempo5.sandicor.com/SNDImages/221/071064797_101_12.jpg" />
And finally, here the javascript I tried invoking from onClick attribute in ImageButton/Input control that didn't work with clearbox (and is not cross browser supported anyway):
<script type="text/javascript">
function clickPhotoLink()
{
document.getElementById("photoLink").click();
}
</script>
My question is this: how do I bring up the clearbox gallery I setup using the list of anchors above from another control such as an input control? I already tried using the onClick attribute (same as onClientClick property for asp.net) on the input to run a script, but had no luck there either invoking a .click() on the the first anchor in the list, nor was I able to rebuild another gallery exactly the same using the "CB_Open('href=mycontent,,parameter2=value 2,,parameter3=value 3,, ... ');" syntax defined on the clearbox page. The .click() won't work since it a) its not consistent across browsers, but b) more so because it's not actually the same as the user clicking the link. Also, using the CB_Open script to rebuild a duplicate gallery didn't seem like a very ideal option (nor could I get it to work) and the .click() just doesn't work with clearbox likely since its not actually the same as a user click.
So, I could change the ImageButton (input control) to be an anchor instead and set the href to the first in the gallery I'm displaying; and then set the other list of anchors to start with image #2 in the list. However, when the user clicks the textual link "View Photos (3)" it will bring up clearbox on the index of the 2nd photo and not the first. So that works, but isn't an ideal solution either since I need it to come up and show the 1st photo (from both places) which wouldn't make sense for clearbox since the href of the anchor points to image 2 and not 1.
Basically, I am wondering if there is a way to bring up my already defined/created clearbox gallery associted with the list of defined anchors on page from another control (possibly even another anchor, but without images from gallery to avoid duplication and/or issue outlined above)?
Any help is greatly appreciated.
stackoverflow answer:
Solved. Instead of using an input control to initiate the click from, I switched it to an anchor control (with an image inside) and set the href attribute to execute the script directly instead of messing with the "onclick" and "rel" (used by clearbox) attributes to bring up the clearbox image gallery.
The resulting html is this:
<img src="http://tempo5.sandicor.com/SNDImages/221/071064797_101_12.jpg" class="mainPhotoImage" />
My asp.net code behind is this:
HtmlAnchor mainPhotoAnchor = new HtmlAnchor();
mainPhotoAnchor.InnerHtml = "<img src=\"" + arrPhotoUrls[0] + "\" class=\"mainPhotoImage\" />";
mainPhotoAnchor.HRef = "javascript:CB_Open('gallery=" + displayAddress + ",,href=" + arrPhotoUrls[0] + "');";
Related
I'm having a bit of an issue figuring out a very simple interaction.
Some Context:
I'm working on a website that showcases some products in a grid and when clicked, a Lightbox pops up with the information of the product..pretty simple! Roughly my markup/script:
<img id="1234" src=".../blah.jpg"></img>
$( img ).click(function() {
// open (this) lightbox
// etc. etc.
});
Now I'm trying to implement the search functionality, which exists obviously in another page. The search reutrn a list of products each one with a path such as:
Product 1234
So if I click the item, it will take me to the correct page where the item exist and since I'm including the anchor link, it will kind of place it visible to the user. This works fine.
My question is, how can I make the Lightbox open automatically after being directed from the search to the actual category page where the product exists?
This seems to be super simple, but for some reason I can't manage to figure it out! Any help would be really appreciated!
Thanks!
So when the dom is ready on the category page, you wan to check the url to see if an anchor exists. This will mean that they have arrived via the search results page.
reference:
How can you check for a #hash in a URL using JavaScript?.
Something like this:
if(window.location.hash) {
var hash = window.location.hash.substring(1); //Puts hash in variable, and removes the # character
alert (hash);
// hash found
// open (this) lightbox
}
If it exists, get the product id from the hashtag and trigger the lightbox functionality
currently I am working on a print button for images which are shown over an overlay. The button itself is already displayed, but I would need the link to the image. The problem is, that there are more links/overlays of this type and that I am really bad in javascript.
Also, the code from the overlay is at the very bottom of the site, so I would need to get the URL from above.
The code, which is clicked, looks like this (where .$largebild. is the url of the image from the database -> I have no access to it at the bottom)
echo '
<div>For the menu of the week click
<span class="zoom-enabled" zoom="<div class=\'overlayplakat\' id=\''.$largebild.'\' name=\'nameOfElement\' style=\'background: url('.$largebild.') no-repeat center center; background-size: contain;\'></div>"> here!</span>
</div>';
What I have planned is, that the script function should get the id, which is the url, where the name is the element which was clicked.
The problem of all that is, that it should be one function for the print button to know where it should get the link and print it like that:
<div id="overlay-print">
<a id="link" href="javascript:getImageLink()" target="_blank">
<i class="icons overlay-button-size">ξΆ</i>
</a>
</div>
I thought there about parameters and probably a help function to identify which element was clicked.
I would be so greatful for help. If you need anything else, just ask.
PS: You should know, that I have posted the same yesterday, but yesterday I only needed one link which worked fine for me. Here is the link: Link for printing image
If you don't want to pass parameters and you want to inline your javascript like your post suggest I think you have at least two options:
Use the DOM structure to figure out what image you want to print.
Mark the appropriate image when it's clicked and print the image with the marker when "print" is clicked.
For option 1, if you have a DOM like:
.div
#url.overlayplakat
%button.print
When the user clicks the print button you can make your javascript search of an adjacent .overlayplakat class pull its ID to get the printable url.
Like so:
function getImageLink() {
var url = $(this).siblings('.overlayplakat').attr('id');
return url;
}
I managed to get some js to work to my surprise, now I want to make it a little more complex which is way out of my expertise.
I have a button when clicked will reload a iframe that is on my page. I have multiple iframes all but 1 are hidden. Then I use jquery to display a different iframe and hidden the previous depending on the nav button clicked. e.g. "1-btn" (nav btn) tied to "1-win" (iframe), "2-btn" (nav btn) tied to "2-win" (iframe) etc. So when you click "2-btn", "1-win" iframe hides and "2-win" iframe is displayed. Now I want to change my code so this ties into my reload javasrcipt. Currently, my js only reloads 1 iframe via the iframe id. I want to change this id every time to a different iframe. This will allow my Reload btn to only reload the current iframe displayed and not any of the other that are hidden.
Here is my Reload js
function Reload () {
var f = document.getElementById('1-win');
f.src = f.src;
}
As you can see this reload script only works for iframe "1-win". When i click "2-btn" nav to display "2-win" iframe (and hides "1-win") the reload button still only works for "1-win". Therefore, I want it to also change. For e.g. when I click "2-btn" (nav) to display "2-win" iframe I want to change the Reload id to "2-win" also.
I was thinking of using onClick within my nav buttons which passed through the id of the iframe which that nav btn is tied to. However, I have no idea how to do this.
For full code see:
https://github.com/tmacka88/Service-Manager
Sorry if this doesn't make any sense, I cant think of an easier way to explain it.
Thanks
EDIT
This below answer may or may not still apply now that the problem has been better defined.
One approach you could try is having a hidden field on the page which contains a semi-colon separated list of the Id's of the iframes. E.g.
<input type="hidden" name="iframeids" value="1;2;3;4;5">
On the click event of your button, call some JavaScript which gets the value of the hidden field, takes the first token before the semicolon, and then reorganise the string. An example:
// Next value is 1
// Use 1 in your JS
// Put 1 to the end, next is now 2
<input type="hidden" name="iframeids" value="2;3;4;5;1">
You would contain the logic of re-arranging etc. in the JS function.
Now that the problem is better defined, we can work out a proper solution.
Here are some design considerations:
Ideally you do not want to manually add a new button for every iframe that you put on the page. Main reason being code maintenance. If you were to add a new iframe, or remove one, your code would not function correctly. Also the amount of mark-up required will be unnecessarily high
jQuery will make your life easier, although it's not required, it will cut out a lot of code. I can't stress enough the importance of knowing JavaScript basics first, but this is your responsibility to learn
For point 1, what we would like is a generic solution so that if you add more iframes, the buttons are added automatically. JavaScript is the way to do this (I'm assuming this is just HTML, not ASP.net or php or some other server side
Point 2 - jQuery will help with point 1.
Now we have this understanding, let's look at an outline of what we need to do:
In JavaScript, loop through the iframe tags on the page
For each iframe, generate a button using jquery, using the values like src and id in the iframe as attributes on the button
Add some click-event code to the button do define what it needs to do when clicked
Again using jQuery, add the newly created buttons to the DOM
This did the trick:
function Reload()
{
$("iframe").each(function()
{
if($(this).is(':visible'))
$(this).attr('src', $(this).attr('src'));
});
}
I have some "Learn More" links on my Home page, all of which correspond to different sections of content that is on the More Info page. These different sections of content are all hidden using display: none.
What I'm wondering is if there's a way to make it so that when I click a particular "Learn More" link, the user will be sent to the More Info page, and the section of content corresponding to the Learn More link they clicked will be shown.
I can't think of a way to achieve this, but I'm hoping it will be possible, perhaps using JavaScript.
EDIT:
The code I currently have is nothing special. Four <a> links on the Home page, then on the More Info page, four divs that are all initially hidden using display: none.
The solution ended up being fairly simple, I did what is described in the top answer of this question: Getting URL hash location, and using it in jQuery
Learn more
<script>
function showContent(id) {
$("#"+id).show();
}
</script>
I think it is possible.You can take the information on a div,and then you click "Learn more",show the div.
In this way,you even needn't a hyperlink,just a click event,like the code upstairs.Of course,this div was hidden before.
One way you can achieve this would be to add a hash to that link with the id of the section you want to show, like this: Learn More. Then just check for it in window.location.hash on the /moreinfo page and show the div.
You have to do it this way: try to use named anchors.
first:
Learn More
when use clicks this link user will navigate to particular page with different sections.
second:
on this page suppose you want to show the 3rd section:
.....
<a name='section-3'></a>
<h1>Your section-3</h1>
In your case divs are hidden then use js or jQuery for this:
As you will get a hash in the location url then use .substr()' and.indexOf()` javascript methods.
try to put this script on those page where you are having your hidden divs
$(function(){
var url = window.location.href;
var obj = url.substr(url.indexOf('#'));
$(obj).show();
});
i have a page on my site (let's call it list_page.html) with js functions that allow you to click a link and see a list of multimedia objects. clicking another link (on the same page) will hide the div with the multimedia list and reveal a list of video objects. another link will hide whatever list is visible and reveal a list of audio objects, and so on...
$("#multibtn").click(function(){
$(".menuslab").hide();
$(".menuslab > *").hide();
$("#multi_div").fadeIn("slow");
$("#multi_div > *").fadeIn("slow");
});
if on my main page (mainpage.html) i have a link named "multimedia", is there a way i can get it to navigate to list_page.html AND execute the function that calls the list of multimedia objects?
Closest way perhaps would be to append a query string to the URI, parse location.hash and see if it's a certain value, and if so trigger that click.