Skip to content Skip to sidebar Skip to footer

How To Create A Popup Box Where Users Can Copy Text?

In my HTML page I generate a link, where users can grab to use for things. I need to somehow give the user the link where they can see the link and then copy the link to clip board

Solution 1:

You could use jQuery ui .dialog()

JS:

$(function() {
    $( "#dialog" ).dialog();
});

HTML:

<div id="dialog" title="Basic dialog">
    <p>This is the default dialog which is useful for displaying information. The dialog window can be moved, resized and closed with the 'x' icon.</p>
</div>

Solution 2:

with jquery you can do something like this

$(function() {
    $( "<div>Your text here </div>" ).dialog();
});

Solution 3:

I'd user a overlaying div, which would appear on a click event. It would contain the text You would like to be able to copy and a close button. (using jQuery!)

First save Your div's content in a string variable. Let us call this variable divCont.

After this we create the overlaying div:

var docHeight = $(document).height();
$("body").append("<div id='overlayDiv'></div>").hide().fadeIn("slow");
$overlayDiv = $("#overlayDiv");
$overlayDiv.height(docHeight).css({
        'opacity' : 0.9,
        'position': 'absolute',
        'top': 0,
        'background-color': 'black',
        'width': '100%',
        'z-index': 5000,
        'margin-left': 10%,
        'margin-right': 10%,
        'color': 'white'
});

Then we append the content of the $overlayDiv with our divCont string and we add a close button to it:

$overlayDiv.append(divCont+"<buttonid='close'>CLOSE</button>'");

After this we add a handler to the close:

$("#close").ready(function(){
   $(document).on("click", "#close", function(){
      $overlayDiv.fadeOut("slow", function(){
         $overlayDiv.remove();
      });
   });
});

Link to working example -> fiddle

Solution 4:

create a fixed div in the middle of the screen (or where ever you want it to be) with a input text box within it. You can trigger this structure whenever you generate a link.

check this fiddle

<div id = "clipboard">
   <input type = "text"></input>
</div>

CSS style would be

#clipboard{
position: fixed;
left: 40%;
top: 40%;
width: 100px;
height: 30px;
border: thin solid grey;

}

#clipboardinput{
    width: 100%;
    height: 100%;

}

Solution 5:

you could use an iframe

    --------opener.html

<html><head><title>modalopener</title><scriptlanguage="JavaScript"type="text/javascript">var modalWin = null;

functionopenModal() {
if (window.showModalDialog) {
modalWin = window.showModalDialog('modalchild.html',null,'dialogWidth=300px;        dialogHeight=200px;  status=0');
}
}

</script></head><body><ahref="javascript:openModal()"><b>open modal window</b></a></body></html>

--------modalchild.html

<html><head><title>Modal Child</title></head><bodyleftmargin="0"topmargin="0"><iframename="modalChild"width="100%"height="100%"src="modaliframe.html"frameborder="0"></iframe></body></html>

--------modaliframe.html

<html><head><title>Modal Iframe</title></head><bodyleftmargin=0topmargin=0bgcolor="pink"><divalign="center"><br><ahref="#"onclick="loadIFrm('http://www.yahoo.com')">yahoo</a><br><ahref="#"onclick="loadIFrm('http://www.google.com')">google</a><br><ahref="#"onclick="loadIFrm('http://www.hotbot.com')">hotbot</a></div><scriptlanguage="JavaScript"type="text/javascript">// call this to reloadfunctionloadIFrm(url) {
location = url;
}
</script></body></html>

Post a Comment for "How To Create A Popup Box Where Users Can Copy Text?"