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().
Related
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!
So i am trying in JS and in HTML to make a button or a tag to open new tab in Default browser Androind and it's not working
This is my html and js code:
HTML
<button class="btn btn-success a-new-tab" data-href="{{ $url }}">My btn</button>
JS
$(document).ready(function () {
$('.a-new-tab').on('click', function (event) {
event.preventDefault();
window.open($(this).attr('data-href'), '_blank');
window.focus();
})
});
Please help me!
I had a same issue on iPhone/iPad Safari browser, so the below solution worked for me. Perhaps, it might help you as well.
HTML
<button class="a-new-tab" data-href="https://www.google.com/">My btn</button>
On button click, I'm getting the data-href and then set onclick attribute to the same button, and inside the attribute opening a new window
$(".a-new-tab").on("click", function () {
var url = $(this).attr("data-href");
$(this).attr( "onclick", "window.open('" + url + "'); return false;" );
});
<a href="" onclick="myFunction('atmosphere-07.pdf')" target="_blank">
Click!
</a>
<br/>
function myFunction(name) {
var myWindow = window.open("", "MsgWindow", "width=1200,height=600");
myWindow.document.write(name);
iFrame = document.getElementById('iFrame').src =name;
myWindow.document.write('<iframe id=iFrame src='name' width='1200' height='900' ></iframe>');
}
Want to open the pdf in new window with document.write call. Want to know how we can pass a variable in the above iframe context
You can try this,
function myFunction(name)
{
var myWindow = window.open("");
myWindow.document.write("<iframe id=iFrame src='"+name+"' width='1200' height='900' ></iframe>");
}
Click! <br/>
It will not run here, on your application it will run, dont use run code snippet button.
you can open directly, you don't need function for that.
Here is an example of what you need
Click!
This will open your PDF in full screen window
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...
I am using a javascript function to navigate away from my website and to another website. I am also trying to open a new page when the button is clicked but instead it navigates on self instead of blank. Why does this happen?
HTML
<p style="text-align:center;">
<input style="font-size:large;" id="btamen" type="button" value="Visit Website">
</p>
JavaScript
<script type="text/javascript">
$("#btamen").click(function() {
window.location.href = 'http://www.google.com'
link.target = '_blank';
});
</script>
This line: window.location.href = 'http://www.google.com' will always replace current page with the new url.
I don't know what is link in the next page, but that code won't even execute because the page redirects and the context is lost.
If you want it like that, then do this:
window.open('http://www.google.com', '_blank').focus();
Also, you cannot guarantee its opening as browser might block it. Sort of kinda pop up blocker.
I don't think you can control it to open in a new tab. So you have to work around, what I did is:
<a href="" target="_blank" id="btamen_link">
<button type="button" id="btamen">
Click
</button>
</a>
And the jquery:
<script type="text/javascript">
$(document).ready(function(){
$('#btamen').click(function(){
$('#btamen_link').attr('href', 'http://www.google.com');
$('#btamen_link').click();
});
});
</script>