a href=javascript:function() in firefox not working - javascript

I tried using a href=javascript:function() in a button, with a function to execute it. It works in Chrome but it doesn't work in Firefox.
Firefox doesn't alert and open blank tab.
Anyone can help me?
<script>
function verifyisbot() {
alert("test.");
var win = window.open("http://yahoo.com", '_blank');
win.focus();
}
</script>
Below is button code
<div class="frb_textcenter">
<a target="_blank" class="frb_button frb_round frb_center frb_fullwidth" href="Javascript:verifyisbot();">
click here
</a>
</div>
Update
I should have added that im using a live editor(profitbuilder) in wordpress to generate the page and button. There is no area for me to insert additional javascript onclick function to the button. So i figure out to use "ahref" blank field in the live editor to input javascript call function to fire up the function.
Is there any way i can make this work through the ahref without using onclick event? Or can i specify onclick function in the ahref field?
Sorry the test() is actually verifybot() function, typo mistake

You can achieve the goal using only the href attribute:
<a href="javascript:void(verifyisbot())" class="frb_button frb_round frb_center frb_fullwidth">
click here
</a>
It works, because when a browser follows a javascript: URI, it evaluates the code in the URI and then replaces the contents of the page with the returned value, unless the returned value is undefined. The void operator can be used to return undefined.

Use onclick event instead of a href=javascript.It works on firefox.See below:
<div class="frb_textcenter">
<a target="_blank" class="frb_button frb_round frb_center frb_fullwidth" onclick="test()">click here</a></div>
<script>
function test() {
alert("test.");
var win = window.open("http://yahoo.com", '_blank');
win.focus();
}
</script>
UPDATE 1: You can do it without use javascript.You just add the link in the href attribute.See below:
<a target="_blank" class="frb_button frb_round frb_center frb_fullwidth" href="http://yahoo.com">click here</a></div>

Give serious consideration to separating your JavaScript and your HTML such that the problem goes away. For instance, add an ID to your anchor and add an event handler through script:
<div class="frb_textcenter">
<a id="verify" target="_blank" class="frb_button frb_round frb_center frb_fullwidth" href="http://yahoo.com">
click here
</a>
</div>
Later...
<script>
function test() {
alert("test.");
var win = window.open("http://yahoo.com", '_blank');
win.focus();
}
window.onload = function () {
document.getElementById('verify').addEventListener('click', test);
};
</script>
Do note that with the example provided, you don't actually need JavaScript at all. The HTML itself will cause a new window/tab to open with Yahoo! loaded...

Related

Update not working for href property in Markdown

I want to create a custom hyperlink which passes current URL as one of the parameter to web app endpoint (abc.azurewebsites.net).
These are the versions I tried with thought process of getting the element by Id and update the href using basic HTML properties but no luck.
Approach 1
> <script> baseurl="abc.azurewebsites.net?="
function buildURL(item) {
> item.href=baseurl+window.location.href;
> return true; }
</script>
> </head> <body> <a onclick="return buildURL(this)" href="">Google</a> </body>
Approach 2
Click on this <a href=""
target="_self" id= "test" onclick = buildURL() >Link </a> to execute
<script>
var el_up = document.getElementById("test");
function buildURL() {
this.href = "abc.azurewebsites.net?=" + document.URL;
}
</script>
Any suggestions please. Is it even possible?
Update: Just to mention, I'm trying this from Azure Devops description section
I believe this will work:
<body>
<a id="link-to-edit" href=""> Click here to execute </a>
</body>
<script>
baseurl="https://abc.azurewebsites.net?="
link = document.getElementById("link-to-edit")
link.href = baseurl + window.location
</script>
This will use javascript to programmatically update the href to the baseurl plus current location as soon as the page/script loads. Then when you click the link will be executed properly. The key is that the href must be set at the time of clicking. In your examples, you set the href AFTER the user clicks and thus the link will not work as you intend. Hope that helps!

target _blank not working with download attribute

I want to open a success page in a new tab after clicking on the download link, but target _blank not working with download attribute. Please Help Me......
Button HTML
<a class="btn download-btn" id="myButton" href="https://www.uiuxstream.com/download/404-error-page-not-found-design-html.html" target="_blank" download>Download</a>
JavaScript
<script type="text/javascript">
document.getElementById("myButton").onclick = function () {
location.href = "/demo/thank-you-for-downloading.php";
};
in the <a>, remove the href, add `onclick="go()", and in a script, add:
function go() {
open("http://www.google.com", "_blank");
location.href = "http://mail.google.com";
}
Good luck!
if you are familiar with event listeners, you could use that instead to call go().

Java Script inline function for Anchor tag

I'm trying to open a URL in new window and want to share the current page address using inline function as below:
a href="javascript:void(0);" onClick='(function()
{
var link = string.concat("example.com/UserStatus.phpid=99244613&utm_source=",window.location.href);
console.log(link);
});return false;'>click here</a>
But nothing is happening, please help.
The problem was that you were using string.concat but the right way to use is "".concat:
function fun(){
var link = "".concat("example.com/UserStatus.phpid=99244613&utm_source=", window.location.href);
console.log(link);
}
fun();
Output will be:
example.com/UserStatus.phpid=99244613&utm_source=https://playcode.io/
HTML:
<a href="javascript:void(0);" onClick='fun();'>click here
</a>
So in your code just use "".concat instead of string.concat.
This works fine.
<a href="javascript:void(0);" onClick="(function(){
var link = ''.concat(`example.com/UserStatus.phpid=99244613&utm_source=`,window.location.href); console.log(link);
return false;
})();return false;">click here
</a>
Working Codepen Link

How to automatically click on a HTML link when opening a new window?

I have a small program in JSP which basically when I click on a document, it opens a new window that allows me to view it. The problem here is it would not show the viewer unless I update or install adobe flash player.
I added a hyperlink link where I can easily click on it and it prompts me to "Allow" to view the document which is fine. The hyperlink looks like below:
<a href="https://get.adobe.com/flashplayer" >Enable Flash</a>
<img border="0" alt="Enable Flash" src="enable_flash.gif"/>
Now, I have to manually click on it, is there a way I can have the hyperlink auto clicked when the pop up windows shows?
I am new to JavaScript and HTML so I figured there is something that I could use like <body onload > .
Edit
This is how my code looks like now:
<body onload="Auto()" > <!--oncontextmenu="return false;"-->
<script>
function Auto(){
<a href="https://get.adobe.com/flashplayer" >Enable Flash</a>
<img border="0" alt="Enable Flash" src="enable_flash.gif"/>
}
</script>
Am I doing anything wrong?
You can simply use click() method
Add id to anchor element
<a href="https://get.adobe.com/flashplayer" id="myLink" >Enable Flash</a>
Add to your script
function automateClick() {
document.getElementById('myLink').click()
}
window.addEventListener("load", automateClick);
Yes..you can use below code and load your link there
$(document).ready(function() {
document.querySelector('a[href="https://get.adobe.com/flashplayer"]').click();
});
OR
$(function() {
document.querySelector('a[href="https://get.adobe.com/flashplayer"]').click();
});
OR
window.onload = function() {
document.querySelector('a[href="https://get.adobe.com/flashplayer"]').click();
}
You can do this with as little as one line, if you want to learn more about the approach I've used, then it may be worth your time looking into functions such as querySelector. Once you have the desired element, you can then simply fire the click method like so.
Demo
<script type="text/javascript">
document.querySelector('a[href="https://get.adobe.com/flashplayer"]').click();
</script>

How to call javascript in href in sharepoint column

I do have a calculated column in sharepoint which creates an anchor tag in which href have a javascript function call to test method but it's not getting called what i am missing here.
Code :
<script type="text/javascript">
function test()
{
alert("hiii");
}
</script>
and calculated column :
<a href='javascript:test()'> Click </a>
Thanks in advance
Pure JS:
function test(){
alert("I am alerted");
}
<a onclick='test()' > Click </a>
jQuery
$(document).ready(function (){
$("#myID").on("click", function (){
alert("I am alerted !");
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<a id="myID" > Click </a>
If I understand, you need to change the display (html generated) of a field in SharePoint.
You are un 2013, you can use JSlink property of your field. With this, you can link a file JS to your field, and this file will be executed every time that sharepoint will generate the rendering of your field.
Check this link to understand how it work and see some exemples ;) : https://code.msdn.microsoft.com/office/Client-side-rendering-JS-2ed3538a
hope this will help you
The attribute in the anchor you are looking for is called onclick:
<a onclick="test()"> Click </a>
This should do the trick I guess.
Check the w3c-schools site for a more detailed description: W3C Schools on the onclick HTML attribute
Please try this way:
<a href='javascript:void(0)' onclick='test()'> Click </a>
<script type="text/javascript">
function test()
{
alert("hiii");
}
</script>

Categories