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

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.

Related

Windows.open append the url to my current page url [duplicate]

This question already has answers here:
Window.open url rewrites the base url two times [closed]
(2 answers)
Closed 2 years ago.
Uder my app ; i m costomising an url to open itin a new window :
myURL = `http://www.google.fr/BB/196?ACTIVITYTEAM=2632&ALLIANCE=FSMG2212&ACTIVITY=VENDEUR/`
weh using
window.open(myURL) ; it doesn't open me that yurl , but i's opening this one :
https://www.google.fr/?http://www.google.fr/BB/196?ACTIVITYTEAM=2632&ALLIANCE=FSMG2212&ACTIVITY=VENDEUR/
as you can see it inject google one extra time in the begining , i want to evitate this
Suggestions ?
i don't understand why is this a problem, your pop up is showing an error?
Anyway, I think you could try this:
var w1 = window.open();
w1.location.href='http://www.google.fr/BB/196?ACTIVITYTEAM=2632&ALLIANCE=FSMG2212&ACTIVITY=VENDEUR/';
Hope it helps you :)

document.getElementById(...) is null in Chrome but working on older browsers like Old IE [duplicate]

This question already has answers here:
Why does jQuery or a DOM method such as getElementById not find the element?
(6 answers)
Closed 4 years ago.
I am getting an error as in the title when I open the console in Chrome and Firefox. However, everything is working fine on older browser like older IE versions. You can check this image.
I am attaching the script:
function MoveNext()
{
var qno = document.getElementById("txtQueNo").value;
var qcode = document.getElementById("txtQueCode").value;
var quetot = document.getElementById("quetot").value;
var que_avl = document.getElementById("que_avl").value;
var stdid = document.getElementById("txtStdID").value;
var oltid = document.getElementById("txtOLTID").value;
var ans = document.getElementById("txtAnswer").value;
var time = document.getElementById("disp").value;
I'm adding the full script for reference.
The issue is on the last line of the above code.
Thank you.
The only occurrence of "disp" in your php is as a name and not an ID (id="txt").
You can use document.getElementsByName("disp")[0].value instead. This will of course return an array of all elements with name="disp" but as you only have one in the php provided, this should be the correct assignment for the 0 based index.

open multiple links in a new windows at once [duplicate]

This question already has answers here:
$window to open multiple links blocked by pop up
(2 answers)
Closed 8 years ago.
how to avoid the link to be blocked by browser popup?
my demo work but it only open the first link, I wonder.. I used foreach..
http://plnkr.co/edit/m8m2I9dqE2kF1H1nzxJT
Added value, key to CB function args and used that to get at the link value, also added the window name attribute telling open function to open blank window each time:
angular.forEach($scope.links, function(value, key){
$window.open("link.html/?" + value.link, '_blank');
});
$scope.links.link was returning "undefined" in that location.

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

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.

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