OK... I have this method that takes care of clicking an anchor. First, here are some things that might need to be clicked:
<a href="javascript:__doPostBack('btnAddNew','')">Add New</a>
<a href="javascript:void(0)" class="SetItemInfo">Some Stuff</a>
<a href="
javascript:__doPostBack('btnDelete','')
" onclick="return Confirm('You want to Delete?')">Delete</a>
<a href="SomeOtherPage.html"
target="
_blank
"
>Get out of here</a>
Now, let's assume that we add click handlers to these anchors:
$("a").click(function(event){return confirm("asdf");});
Ok. So my question!
Does this handle things in the correct order?
function clickAnchor(anchor) {
$(anchor).click(doHrefClick).click().unbind("click", doHrefClick);
}
function doHrefClick() {
var href = this.getAttribute('href'), target = this.getAttribute('target'); if (href != "#") { if (target != "" && href.indexOf("javascript:") != 0) window.open(this.getAttribute('href'), target); else document.location = this.getAttribute('href'); } }
I'm assuming that OnClick handlers should happen before the Href should. And if any of them return false, I believe it would stop propagating the later handlers, including the Href. I haven't played with the target much... is there a good way to deal with an item if it has a target like "_parent" or "CustomPopupPageName"? Just trying to think of how to make this generic.
Edit: updated slightly. It seems to work with targets now. Not sure if I should just replace target with "_self" when it is blank. Thoughts?