Adding onclick() to link in drupal 7
up vote
0
down vote
favorite
I’m working in adding an onclick
attribute to a few links on my drupal 7 site. I added the menu_attributes
module to assign an id to my links, tried adding the following code to a new js file I included in sites/themes/themeName.info
.
function() {
var link = document.getElementById('conversion');
//link.setAttribute("target", "_blank");
link.addEventListener("click", function(e){
return gtag_report_conversion('http://www.mysite/page’); }); }
It’s not adding onclick, would greatly appreciate any help.
javascript drupal google-analytics
add a comment |
up vote
0
down vote
favorite
I’m working in adding an onclick
attribute to a few links on my drupal 7 site. I added the menu_attributes
module to assign an id to my links, tried adding the following code to a new js file I included in sites/themes/themeName.info
.
function() {
var link = document.getElementById('conversion');
//link.setAttribute("target", "_blank");
link.addEventListener("click", function(e){
return gtag_report_conversion('http://www.mysite/page’); }); }
It’s not adding onclick, would greatly appreciate any help.
javascript drupal google-analytics
add a comment |
up vote
0
down vote
favorite
up vote
0
down vote
favorite
I’m working in adding an onclick
attribute to a few links on my drupal 7 site. I added the menu_attributes
module to assign an id to my links, tried adding the following code to a new js file I included in sites/themes/themeName.info
.
function() {
var link = document.getElementById('conversion');
//link.setAttribute("target", "_blank");
link.addEventListener("click", function(e){
return gtag_report_conversion('http://www.mysite/page’); }); }
It’s not adding onclick, would greatly appreciate any help.
javascript drupal google-analytics
I’m working in adding an onclick
attribute to a few links on my drupal 7 site. I added the menu_attributes
module to assign an id to my links, tried adding the following code to a new js file I included in sites/themes/themeName.info
.
function() {
var link = document.getElementById('conversion');
//link.setAttribute("target", "_blank");
link.addEventListener("click", function(e){
return gtag_report_conversion('http://www.mysite/page’); }); }
It’s not adding onclick, would greatly appreciate any help.
javascript drupal google-analytics
javascript drupal google-analytics
edited Nov 8 at 20:33
asked Nov 8 at 19:27
hvannia
12
12
add a comment |
add a comment |
2 Answers
2
active
oldest
votes
up vote
0
down vote
Check whether the script is loading in the page. See this for the details of adding javascript in drupal 7.
I included the 'Add to Head' module to add the other .js scripts. This one I've been trying to test it in developer console. I get the element but the error occurrs when trying to add "onclick()"
– hvannia
Nov 9 at 4:04
$('#conversation').on('click',function(){ //Code here } Could you try this?
– Meera
Nov 9 at 4:08
I found this link, I think this is my issue, the script is looking for something not yet existing, stackoverflow.com/questions/14028959/… . Option 1 did not work for me.
– hvannia
Nov 10 at 14:59
add a comment |
up vote
0
down vote
Based on JavaScript that executes after page load and adjusted for this specific problem this code works if placed inside head
function addClick(){
alert('click'); //confirm it works
return gtag_report_conversion('http://mySite/myPage');
}
//make sure this runs after dom is loaded.. so element can be found
document.addEventListener("DOMContentLoaded", function(){
var link = document.getElementById("cteconversion");
link.onclick=addClick;
});
add a comment |
2 Answers
2
active
oldest
votes
2 Answers
2
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
0
down vote
Check whether the script is loading in the page. See this for the details of adding javascript in drupal 7.
I included the 'Add to Head' module to add the other .js scripts. This one I've been trying to test it in developer console. I get the element but the error occurrs when trying to add "onclick()"
– hvannia
Nov 9 at 4:04
$('#conversation').on('click',function(){ //Code here } Could you try this?
– Meera
Nov 9 at 4:08
I found this link, I think this is my issue, the script is looking for something not yet existing, stackoverflow.com/questions/14028959/… . Option 1 did not work for me.
– hvannia
Nov 10 at 14:59
add a comment |
up vote
0
down vote
Check whether the script is loading in the page. See this for the details of adding javascript in drupal 7.
I included the 'Add to Head' module to add the other .js scripts. This one I've been trying to test it in developer console. I get the element but the error occurrs when trying to add "onclick()"
– hvannia
Nov 9 at 4:04
$('#conversation').on('click',function(){ //Code here } Could you try this?
– Meera
Nov 9 at 4:08
I found this link, I think this is my issue, the script is looking for something not yet existing, stackoverflow.com/questions/14028959/… . Option 1 did not work for me.
– hvannia
Nov 10 at 14:59
add a comment |
up vote
0
down vote
up vote
0
down vote
Check whether the script is loading in the page. See this for the details of adding javascript in drupal 7.
Check whether the script is loading in the page. See this for the details of adding javascript in drupal 7.
answered Nov 9 at 3:22
Meera
1026
1026
I included the 'Add to Head' module to add the other .js scripts. This one I've been trying to test it in developer console. I get the element but the error occurrs when trying to add "onclick()"
– hvannia
Nov 9 at 4:04
$('#conversation').on('click',function(){ //Code here } Could you try this?
– Meera
Nov 9 at 4:08
I found this link, I think this is my issue, the script is looking for something not yet existing, stackoverflow.com/questions/14028959/… . Option 1 did not work for me.
– hvannia
Nov 10 at 14:59
add a comment |
I included the 'Add to Head' module to add the other .js scripts. This one I've been trying to test it in developer console. I get the element but the error occurrs when trying to add "onclick()"
– hvannia
Nov 9 at 4:04
$('#conversation').on('click',function(){ //Code here } Could you try this?
– Meera
Nov 9 at 4:08
I found this link, I think this is my issue, the script is looking for something not yet existing, stackoverflow.com/questions/14028959/… . Option 1 did not work for me.
– hvannia
Nov 10 at 14:59
I included the 'Add to Head' module to add the other .js scripts. This one I've been trying to test it in developer console. I get the element but the error occurrs when trying to add "onclick()"
– hvannia
Nov 9 at 4:04
I included the 'Add to Head' module to add the other .js scripts. This one I've been trying to test it in developer console. I get the element but the error occurrs when trying to add "onclick()"
– hvannia
Nov 9 at 4:04
$('#conversation').on('click',function(){ //Code here } Could you try this?
– Meera
Nov 9 at 4:08
$('#conversation').on('click',function(){ //Code here } Could you try this?
– Meera
Nov 9 at 4:08
I found this link, I think this is my issue, the script is looking for something not yet existing, stackoverflow.com/questions/14028959/… . Option 1 did not work for me.
– hvannia
Nov 10 at 14:59
I found this link, I think this is my issue, the script is looking for something not yet existing, stackoverflow.com/questions/14028959/… . Option 1 did not work for me.
– hvannia
Nov 10 at 14:59
add a comment |
up vote
0
down vote
Based on JavaScript that executes after page load and adjusted for this specific problem this code works if placed inside head
function addClick(){
alert('click'); //confirm it works
return gtag_report_conversion('http://mySite/myPage');
}
//make sure this runs after dom is loaded.. so element can be found
document.addEventListener("DOMContentLoaded", function(){
var link = document.getElementById("cteconversion");
link.onclick=addClick;
});
add a comment |
up vote
0
down vote
Based on JavaScript that executes after page load and adjusted for this specific problem this code works if placed inside head
function addClick(){
alert('click'); //confirm it works
return gtag_report_conversion('http://mySite/myPage');
}
//make sure this runs after dom is loaded.. so element can be found
document.addEventListener("DOMContentLoaded", function(){
var link = document.getElementById("cteconversion");
link.onclick=addClick;
});
add a comment |
up vote
0
down vote
up vote
0
down vote
Based on JavaScript that executes after page load and adjusted for this specific problem this code works if placed inside head
function addClick(){
alert('click'); //confirm it works
return gtag_report_conversion('http://mySite/myPage');
}
//make sure this runs after dom is loaded.. so element can be found
document.addEventListener("DOMContentLoaded", function(){
var link = document.getElementById("cteconversion");
link.onclick=addClick;
});
Based on JavaScript that executes after page load and adjusted for this specific problem this code works if placed inside head
function addClick(){
alert('click'); //confirm it works
return gtag_report_conversion('http://mySite/myPage');
}
//make sure this runs after dom is loaded.. so element can be found
document.addEventListener("DOMContentLoaded", function(){
var link = document.getElementById("cteconversion");
link.onclick=addClick;
});
answered Nov 12 at 5:17
hvannia
12
12
add a comment |
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53214826%2fadding-onclick-to-link-in-drupal-7%23new-answer', 'question_page');
}
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown