How do MSDN web pages access the clipboard?

S

Steve Richter

I am using the window.clipboardData.getData javascript method to copy
from the clipboard.

<SCRIPT LANGUAGE="JavaScript">
function ShowClipBoard()
{
var data = window.clipboardData.getData("text") ;
alert( data ) ;
}

</SCRIPT>

This works, but I am not prompted by the browser first, asking if I
want to allow access to the clipboard.

When I click "copy code" from an MSDN web page I first am prompted by
a browser message box asking if I want to allow access to the
clipboard.
http://msdn2.microsoft.com/en-us/library/ms533044.aspx

What method would the MSDN page be using to access the clipboard that
would cause the "allow access" prompt?

Is it just that I am running my test page from localhost? I want to
make sure I am using the most standards compliant method to copy to
and from the clipboard.

thanks,

-Steve
 
M

Mark Rae

What method would the MSDN page be using to access the clipboard that
would cause the "allow access" prompt?

I don't actually know the answer, so what follows is just theory...

Firstly, the CopyCode function doesn't appear in the page's View Source, so
I'm guessing it's in some JavaScript include file...Therefore, it's
impossible to tell what it's doing without some serious hacking...

Secondly, this appears to be an IE-only thing - the "Copy Code" hyperlinks
don't appear at all when the page is viewed in any other browser, even the
very latest version of FireFox (2.0.0.4)...

Thirdly, I'm not actually certain that it's doing anything cleverer than
popping a showModalDialog and storing the return value in a JavaScript
variable... Simple enough to do but, of course, showModalDialog is not
cross-browser compatible and most certainly not standards-compliant...
Curiously enough, the "Copy Code" hyperlinks don't appear on Safari either,
even though showModalDialog *is* supported on that browser - draw your own
conclusions there... ;-)
I want to make sure I am using the most standards compliant method

In which case, you need to change your <script> tag to:

<script type="text/javascript">
....
....
</script>

as the language tag is deprecated in XHTML...

Upper-case tag properties aren't supported either...
 
G

Guest

Is it just that I am running my test page from localhost?

yes, it asked you on the MSDN site because of IE settings

Tools - Internet Options - Security - Internet - Custom level

Scroll down to "Scripting", "Allow Programmatic clipboard access"
 
S

Steve Richter

I don't actually know the answer, so what follows is just theory...

Firstly, the CopyCode function doesn't appear in the page's View Source, so
I'm guessing it's in some JavaScript include file...Therefore, it's
impossible to tell what it's doing without some serious hacking...

Secondly, this appears to be an IE-only thing - the "Copy Code" hyperlinks
don't appear at all when the page is viewed in any other browser, even the
very latest version of FireFox (2.0.0.4)...

Thirdly, I'm not actually certain that it's doing anything cleverer than
popping a showModalDialog and storing the return value in a JavaScript
variable... Simple enough to do but, of course, showModalDialog is not
cross-browser compatible and most certainly not standards-compliant...
Curiously enough, the "Copy Code" hyperlinks don't appear on Safari either,
even though showModalDialog *is* supported on that browser - draw your own
conclusions there... ;-)


In which case, you need to change your <script> tag to:

<script type="text/javascript">
...
...
</script>

as the language tag is deprecated in XHTML...

Upper-case tag properties aren't supported either...

--http://www.markrae.net

thanks. onward, to the next challenge ...
 
R

Ray Booysen

What you can do is this:

function ShowClipBoard()
{
if ( confirm("Do you want to copy this to the clipboard?"))
{
var data = window.clipboardData.getData("text") ;
alert( data ) ;
}
}

Cheers!
Ray
 
G

George Ter-Saakov

I positive it's because localhost is the different zone (Local intranet)
than microsoft.com which's in Internet.
And different zones have different security settings

so as soon you move your code to domain.com you will be prompted as well

George.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,994
Messages
2,570,223
Members
46,812
Latest member
GracielaWa

Latest Threads

Top