I want to add JavaScript attribute “onclick” with “go to” function inside a “span” tag: onclick=”GoTo(‘URL’) to a post on WordPress website.
When I add this code to a post:
<span class="aff" onclick="GoTo('URL')" target="blank">text</span>
nothing happens when you click on the "text" and there is an error “Uncaught ReferenceError: GoTo is not defined at HTMLSpanElement.onclick” at the console.
Please, help to fix the issue.
Add this ->
<script type="text/javascript">
var GoTo=function(url){
window.location.replace(url);
}
</script>
Can you add the code for your Goto function hard to know what wrong without that?
Assume something like
function GoTo(url){
window.location = url;
}
Related
So I'm trying to load my homepage HTML file after it a certain time frame. This is what I have right now:
reply.file('./views/afteradd.html');
setTimeout( function(){
window.location.href= "views/add.html";
}, 1000);
I want to load my add.html file after certain period however when I try to create a path to the my file I get an error. I have tried window.location and tried *.href. I'm pretty new in Java Script so it might be a really simple error im not finding.
The error I'm getting is:
"Debug: internal, implementation, error
ReferenceError: window is not defined"
If your add.html is not present in root location then please give full path in href
For this please try below code :
<script>
setTimeout(function(){window.location.href='http://yourdomainname/views/add.html'},1000);
</script>
And for home page add only '/'
<script>
setTimeout(function(){window.location.href="/"},1000);
</script>
Hello try with this.
<script>
var change_path = function(){window.location.href="/"};
setTimeout(change_path ,1000);
</script>
So I am trying to simulate a link click when a button is clicked, but nothing seems to happen when executing the code.
<a id=“preface” href=https://localhost:443/6.5.1> 6.5.1 </a>
<button id=“auto” onclick="myFunction()">Click</button>
<script>
function myFunction() {
document.getElementById(“preface”).click();
}
</script>
I should mention that the template file containing this code is used and executed by Golang with:
s1, _ := template.ParseFiles("html_file")
s1.ExecuteTemplate(w, "html_file", nil)
I do not know why it does not work, because when I try doing an alert action it works, while even if I try opening a window for www.google.com it does not work.
That's not how you redirect using js. try to use window.location.
Something like:
function myFunction() {
var link = document.getElementById("preface").getAttribute("href");
window.location.href = link;
}
Edit:
Plunker here:
https://plnkr.co/edit/AP7MV51LdRs43HFIQngw?p=preview
If you see in the console..network tab you should see a call to google.co.uk
Thank you for your help! Apparently the problem was that the id value was written with quotes "preface". When I wrote it:
id = preface
it worked. I do not understand why, since as far as I know both href and id should have their values in quotes, but it seems that it only works this way.
Thank you again!
I hope you have well with nice pleasure.
I am trying to remove Script tag by ID. For this purpose, I am apply code
var elem = document.getElementById("sns_scripts");
elem.remove();
But, this is give me error on my console windows is :
Uncaught TypeError: Cannot read property 'remove' of null
I am trying another method is :
$("#sns_scripts").remove();
It is also not working. See Picture
Picture is mention , sns_scripts script still avaialbe, and above this script my custom code, but it is not working.
Please help me, I am really want to remove sns_scripts script from my webpage.
Wrap your code within DOMContentLoaded event:
document.addEventListener('DOMContentLoaded', function(){
var elem = document.getElementById("sns_scripts");
elem.remove();
});
Because you are trying to get an element at that point where is wasn't available in the DOM. So, it was null.
do not use elem.remove(), but use
$(elem).remove();
NOTE: Re-order following lines in your code. Because you are running remove() function before writing script with id(sns_script):
<script type="text/javascript" id="sns_scripts">var video=document.getElementById('bgvid');</script>
<script>
$('#sns_scripts').remove();
</script>
Google Developer Tools is displaying the following error when my PHP page uses the content from a javascript file (my_scripts.js):
"Uncaught ReferenceError: $ is not defined scripts.js:1 (anonymous function)"
Content of my_scripts.js
$('a.button').click(function(){
window.location.href = "another_page.php";
});
The page and the script work as required. Clicking the element links to the requested page, but the error is there.
1) What causes the error?
2) Can it or should it be ignored?
1) It looks like your problem is that jQuery haven't been loaded.
Make sure you load jQuery before scripts.js.
<head>
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.2/jquery.min.js"></script>
</head>
2) Errors should never be ignored.
You need to load jquery libary BEFORE! Please download the jquery.min.js at http://www.jquery.com/download/
also, write like this:
$(doucment).ready(function(){
$('a.button').on('click',function(){
window.location.href = "another_page.php";
});
});
If you have already included jQuery on your file, and still its not working you should try,
jQuery(doucment).ready(function(){
jQuery('a.button').on('click',function(){
window.location.href = "another_page.php";
});
});
This is causing as there might be some conflicting js files.
I have a link that I want to change with Javascript. I've got it working but I want it to all be done on just one line. I must be writing the syntax wrong.
This is what I've got working:
function buttonOne(){
window.location.href='http://www.' + brand() + '.com/';
}
Agent Stats
Ok and when I tried to combine them like this it didn't work:
Agent Stats
I'm sure I've just got the syntax wrong... Any ideas on how to write it so that it works fine?
Your syntax is correct. Using the exact code below works. You'll need to provide more details on the behavior you're experiencing. Are there any errors in the javascript console in your debugger? Does the brand function exist and does it return anything useful?
<html>
<head>
<script>
function brand() { return 'google'; }
</script>
</head>
<body>
Agent Stats
</body>
</html>
EDIT: The debugger is your friend. "Object is not a function" - referring to the anchor tag brand() function call. This is because you have a form with the same name. Rename the form to brand2 and it works fine. http://jsfiddle.net/k6LFB/