Presto-X Posted April 15, 2012 Share Posted April 15, 2012 Hello everyone, I’m trying to get the "rel" attribute information from a selected image within an iframe but have not had much luck. Would it be easier to have the rel on the image itself or on the link that wraps the image? I do not JavaScript at all and I was not sure the best way to go about this, I'm trying to get the rel tag information then append that data to the end of a link that will open a lightbox, then in the lightbox iframe I have a PHP from that will get that data from the URL and auto populate it in to the appropriate fields. I'm a ok with PHP/mySQL but SUCK with JavaScript so any help or suggestions would be greatly appreciated. The button I'm trying to append the data to id is "myButton". Here is some of the crappy code I have been playing around with, please do have a good chuckle as I state above I have no clue when it comes to JavaScript but I'm learning LOL. /*function selectedText(input){ var iframe = document.getElementById("jform_articletext_ifr"); var idoc = iframe.contentDocument || iframe.contentWindow.document; var startPos = idoc.input.selectionStart; var endPos = idoc.input.selectionEnd; var doc = document.idoc.selection; if(doc && doc.createRange().text.length != 0){ alert(doc.createRange().text); }else if (!doc && input.value.substring(startPos,endPos).length != 0){ alert(input.value.substring(startPos,endPos)) } }*/ function selectedText(){ var win = document.getElementById("jform_articletext_ifr").contentWindow; var doc = win.document; /*var dgs = doc.selection; var div1 = doc.getElementById("myImage"); var dga = dgs.getAttribute("href");*/ if (win.getSelection){ txt = win.getSelection().getAttribute("href"); }else if (doc.getSelection){ txt = doc.getSelection().getAttribute("href"); }else if (doc.selection){ txt = doc.selection.createRange().getAttribute("href"); } alert(txt); if(win.selection.getContent){ alert(win.selection.getContent().toString()); }else if(doc.selection.getContent && doc.selection.createRange){ alert(doc.selection.getContent.createRange().text); } } Quote Link to comment https://forums.phpfreaks.com/topic/260956-get-rel-attribute-from-selected-image-within-an-iframe/ Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.