Issue
I’ve got a span tag:
<span id="myBtnfb"
class="demo" onclick="open()">
<span class="icon"> </span>
<span class="">Testing</span>
</span>
and some javascript
function open() {
alert('Hello');
}
Now, what I want to happen is when the span is clicked, it fires the function “open”. What seems to happen though is it just reloads the page but brings back a blank page. Any ideas?
Solution
open()
is a native JavaScript function, which opens a new page (in this case blank since there’s no params specified): https://developer.mozilla.org/en-US/docs/Web/API/Window/open
Just rename your function to something like openAlert()
: http://jsfiddle.net/qtf5s/2/.
Also, @Ian mentioned in the comments that in JSFiddle, it’s best to change the JavaScript wrap to "No wrap – in " so that the code works.
Answered By – Alfred Xing
This Answer collected from stackoverflow, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0