Jump to content

Recommended Posts

 

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);
}
}

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.