Reputation: 1996
I have a class of links which when clicked launch a modal window. Within the modal window how can I access the href of the object which spawned the modal? My goal is to use a button within the modal window which, when clicked will open a window to the href of the caller.
I don't need code to display the modal window for this class of links, just how to acccess values from the parent object.
thanks
Example as requested:
<li><a href="http://foo" rel="ExtLink">blah</a></li>
<li><a href="http://bar" rel="ExtLink">Test</a></li>
Modal:
<div class="modal fade" id="ModalTest" tabindex="-1" role="dialog" aria-labelledby="ModalTestLabel" aria-hidden="true">
<div class="modal-dialog">
<div class="modal-content">
<div class="modal-header">
<button type="button" class="close" data-dismiss="modal" aria-hidden="true">×</button>
<h4 class="modal-title" id="ModalTestLabel">External URL warning</h4>
</div>
<div class="modal-body">
External URL warning here.
</div>
<div class="modal-footer">
<button type="button" class="btn btn-default" data-dismiss="modal">Exit</button>
<button type="button" class="btn btn-primary">I understand, visit link</button>
</div>
</div><!-- /.modal-content -->
</div><!-- /.modal-dialog -->
</div><!-- /.modal -->
Open from JS:
$("a[rel='ExtLink']").click(function(e){
$('ModalTest').show();
});
So if I click either of these a modal window opens. Within the modal window I want a button that when pressed launches the href of the caller. Thanks
Upvotes: 0
Views: 6185
Reputation: 3385
Try this,
$(document).on("click", "ul li a", function (e) {
e.preventDefault();
e.stopPropagation();
var link = $(this).attr('href');
$("#myModal a").attr('href',link);
$(".moadl").modal("show");
});
html
<ul>
<li><a href="http://foo" rel="ExtLink">blah</a></li>
<li><a href="http://bar" rel="ExtLink">Test</a></li>
</ul>
<div class="modal hide" id="myModal">
<div class="modal-header">
<button class="close" data-dismiss="modal">×</button>
<h3>Modal header</h3>
</div>
<div class="modal-body">
<a href="">go to link</a>
</div>
</div>
Upvotes: 3