Jump to content

How to copy code


Thomas P

Recommended Posts

Posted

Hi mates,

I did a search and couldn't find anything to my basic question admittedly simple question:

How can I copy code posted in a post, i.e. a block of code, all at once?

Thanks,
Thomas

Posted

Hi folks,

maybe a sample helps to explain or gives someone the opportunity to tell me how to copy that line correctly:

 

Get-Content c:serverlist.txt | ForEach-Object {Get-WinEvent -LogName System -maxevent 3 -FilterXPath ‘*[System[(EventID=1074)]]’ –ComputerName $_} | format-table machinename, userid, timecreated –autosize

That is a one-liner and imo hard to copy - unless you have a hint how to do it right, i.e. correctly.

Thanks,
Thomas

Posted

Not sure, if I understand your issue...

To copy the code:

  1. Click on "quote" and it will be displayed in your editor. After that you could delete other text around it.
  2. Triple click on the "code line" (= 3 fast clicks on the content line) and copy it (CTRL+C). Tripple clicking selects the whole line / paragraph, at least in MS windows
Posted
1 hour ago, Thomas P said:

That is a one-liner and imo hard to copy - unless you have a hint how to do it right, i.e. correctly.

I click inside the paragraph and drag down until the end of the paragraph. If it’s just one line, the way to drag down is short, but it works just the same. That selects the whole line. 

Posted
1 hour ago, Cyboman said:

Triple click on the "code line" (= 3 fast clicks on the content line) and copy it (CTRL+C). Tripple clicking selects the whole line / paragraph, at least in MS windows

I like that one, thanks.

What I mean is something more convenient, like here:
https://stackoverflow.com/questions/22581345/click-button-copy-to-clipboard-using-jquery try the example, it uses pretty basic HTML.

You surely have seen websites where code is posted and there is a button/icon next to it, where you can Copy the code instantly to your clipboard.

Especially for scripting/coding forums that would be helpful. 

 

Posted

Quick bit of code....basis for you to build on....

<script type="text/javascript">
$(document).ready(function(){
  $("pre.ipsCode").append("<i class='fa fa-clipboard neCodeCopy' style='float:left';></i>");
  $("i.neCodeCopy").on('click',function(e){
   	var $neTemp = $("<textarea>");
   	$("body").append($neTemp);
   	$neTemp.val($(this).parent(".ipsCode").text()).select();
   	document.execCommand("copy");
   	$neTemp.remove();
  });
});
</script>

Add that in via the Google Analytics tracking code box.

image.thumb.png.aa2b11b6058b6d3d5d9baf3c7372af1a.png

Archived

This topic is now archived and is closed to further replies.

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...