Copying an image to clipboard using JavaScript/jquery [duplicate] - javascript

This question already has answers here:
Copy Image to Clipboard from Browser in Javascript?
(4 answers)
Closed 8 years ago.
I need to copy an image to clipboard using JavaScript/jquery and I am using the following js to achieve that.
function copyImageToClipBoard() {
var div = document.getElementById('chart1');
div.contentEditable = true;
var controlRange;
if (document.body.createControlRange) {
controlRange = document.body.createControlRange();
controlRange.addElement(div);
controlRange.execCommand('Copy');
}
div.contentEditable = false;
}
It works fine locally in IE. But when I tried to test it from other machines IE, to paste the image into MS word I need to use the Paste Special-> Device Independent Bitmap option, otherwise I cannot see the image pasted.
I was wondering if it has anything to do with the environment of the m/c. If so is there any other option which works anywhere?

Clipboard access on the web is not desirable because of the security implications.

Related

Unsafe assignment to innerHTML [duplicate]

This question already has an answer here:
Best way to purge innerHTML from a Firefox Extension
(1 answer)
Closed 2 years ago.
I was trying to get an add on for Firefox signed by Mozilla so I could use it on the stable version of firefox and I'm getting this validation issue.
Can someone help me understand what it is?
Unsafe assignment to innerHTML
Warning: Due to both security and performance concerns,
this may not be set using dynamic values which have not been adequately sanitized.
This can lead to security issues or fairly serious performance degradation.
datetime.js line 4 column 5
function updateClock(){
var doc=window.content.document
var dt = new Date();
doc.getElementById("datetime").innerHTML = dt.toLocaleTimeString();
}
setInterval(updateClock, 0);
dt.toLocateTimeString() return a String instead of HTML.
Instead of, use innerText or textContent:
doc.getElementById("datetime").innerText = dt.toLocaleTimeString();
doc.getElementById("datetime").textContent = dt.toLocaleTimeString();

How to detect whether browser supports :invalid pseudoclass? [duplicate]

This question already has answers here:
Test if a browser supports a CSS selector
(5 answers)
Closed 8 years ago.
I tried to use Modernizr, but it seems not to support this feature detection.
I also read that it is difficult or even inmpossible to access pseudoclasses from javascript, because they are not part of DOM. So, after surfing the web I found no relevant information.
I need an easy solution without the need to download heavy libraries.
Can anybody help me with this?
Thanks
Trap an error from querySelector or matches, which parses the selector and throws an error if it is not valid:
function invalid_pseudoclass_support () {
var support = true;
try {
document.querySelector(':invalid');
} catch (e) {
support = false;
}
return support;
}

javascript events not working with Chrome Extension , why ! :/ [duplicate]

This question already has answers here:
Port error while changing chrome extension from manifest v1 to v2
(2 answers)
Closed 8 years ago.
HTML // code
input id ="submit_btn" type="submit" value="find" onclick="goto();"
Javascript / code
function goto()
{
if (document.getElementById("s_keyword").value != "") {
var url = ("https://www.youtube.com/results?search_query=" + document.getElementById("s_keyword").value);
var site = window.open(url, '_blank');
site.focus();
}
};
it never enters into goto function !
Chrome extensions don't support inline events. Add the event listener in your JavaScript, and it'll be fine:
document.getElementById('submit_btn').addEventListener('click', goto);
You may want to avoid using goto as your function's name too. It may be a reserved keyword.

PHP $_Get and JQuery .load [duplicate]

This question already has answers here:
Encode URL in JavaScript
(22 answers)
Closed 8 years ago.
I want to load another page via Javascript like this
$("#resultarea").load("searchresults.php?searchstring=" + $("#searchbox").val());
in searchresults.php, a single statement
echo $_GET["searchstring"];
what I type in searchbox appears when searchresults.php is loaded except when I add space and another word, no thing appear at all. I heared it can be done by encoding or somewhat, I searched but didn't find a solution.
Try encodeURIComponent:
var encodedValue = encodeURIComponent($("#searchbox").val());
$("#resultarea").load("searchresults.php?searchstring=" + encodedValue);
Source
Demo

document.createElement throwing error in IE 8. This command is not Supported ERROR [duplicate]

This question already has answers here:
Closed 11 years ago.
Possible Duplicate:
Javascript doesn't work in IE8
I have the following code
var ind=1;
try
{
rdo = document.createElement('<input type="radio" name="radioOptions" />');
}
catch(err)
{
rdo = document.createElement('input');
}
rdo.setAttribute('type','radio');// error
rdo.setAttribute('name','radioOptions');
rdo.id = 'radioOption_'+ind;
rdo.value = ind;
After a thorough checkup this line is throwing error on IE 8
rdo.setAttribute('type','radio')
and a strange fact is that when it is on the local system its not doing that.
I am dynamically adding this radio input to the form. And the Doc type i have set to
<!doctype html>
Any Idea what should work for all Browsers including the ASS HOLE IE
You can not change the type of input elements in IE with setAttribute(). You could try with rdo.type = 'radio' (which should work) or (ugh) innerHTML.
Also, document.createElement() is used with the element's name, i.e. input. It is not like $() in jQuery or similar libraries.

Categories

Resources