Forum Moderators: open

Message Too Old, No Replies

jQuery: Look for rel="SomeName" in a link to open in new window

         

WannaKnowSEO

10:15 pm on Oct 31, 2008 (gmt 0)

10+ Year Member



I'm using shadowbox, which works great for browsers, but horribly for iPhones. I just added some new code:

---

if ($.iPhone.present) {
}
else {
Shadowbox.init(options);
}

---

This prevents shadowbox from overriding the rel="shadowbox" attribute on a link. But I'd like to take it one step further, and have rel="shadowbox" convert the href to basically target="_blank", or use javascript to open it in a new window. This would effectively make the links open in new tabs for the iphone.

Does anyone know the jquery code to do this, or at least the code to identify all the links with rel="shadowbox" ?

Thanks in advance for your time!

WannaKnowSEO

11:00 pm on Oct 31, 2008 (gmt 0)

10+ Year Member



I think I found more information. Line 461 on shadowbox.js is:

rel: /^(light¦shadow)box/i, // rel attribute format

If I update that line to:

rel: /^nofollow (light¦shadow)box/i, // rel attribute format

Then it'll match rel="nofollow shadowbox". What I still can't figure out is how to make it accept rel="shadowbox" AND/OR rel="nofollow shadowbox".

Any ideas?

astupidname

11:09 pm on Oct 31, 2008 (gmt 0)

10+ Year Member



I don't know much about JQuery, but is something like this what you are looking to do?:

script type="text/javascript">
/*<![CDATA[*/ /*for valid xhtml*/
window.onload = function(){
var linksArray = document.getElementsByTagName("a");
for (var i = 0; i < linksArray.length; i++){
if (linksArray[i].rel === "shadowbox"){
linksArray[i].target = "_blank";
}
}
}
/*]]>*/
</script>

Place that in the head of a document and it will give a target="_blank" attribute to all links on the page with a rel="shadowbox" attribute.