I have a link that opens a small popup (not a new tab) to a page.
I would like to integrate this function into a button. Unfortunately this doesn't work as hoped.
Good example link:
<a href='#' onclick='window.open **
("https://google.com","mywindow",
"menubar=1,resizable=1,width=500,height=500")'>
Link</a>
Current button that should do the same:
<form>
<input class="btnstylega" onclick="window.location.href='https://google.com'" type="button" value="Link" />
</form>
why you not try:
<form><input class="btnstylega" onclick="window.open('https://google.com','mywindow',
'menubar=1,resizable=1,width=500,height=500')"
type="button" value="Neue Versicherung hinzufügen" /></form>
Use _blank with the target attribute; this will open a new tab:
<form>
<input class="btnstylega" type="button" value="Neue Versicherung hinzufügen" target="_blank" />
</form>
Or if you want to open a new window, use the onClick attribute:
<button class="button" onClick="window.open('http://www.example.com');">
<span class="icon">Open</span>
</button>
Here, do NOT forget the quotation marks around the "window.open('http://www.example.com');".
This is happening because you are setting the window location in one and not creating a new window.
This amended code should work as intended:
<form><input class="btnstylega"
onclick="window.open('https://google.com','mywindow',
'menubar=1,resizable=1,width=500,height=500')"
type="button" value="Link" /></form>
Related
I have this piece of code:
<button name='link' onclick="window.location.href = 'Text.html';"
style="cursor:pointer" class='Text' value='Text.html' title='Text'>Text</button>
On click it will take you to one of my sub-sites. I wanted it to open the link in a new tab so I tried putting target='_blank' in the button tag, but it didn`t work. If possible I would prefer to use HTML.
Thanks
What about using form
<form action="//example.com/Text.html" target="_blank">
<button type="submit">Text</button>
</form>
This can take to different site or any of your sub-site.
Replace button tag with a
Text
Edit: While the original answer works, it isn't in line with the W3C HTML5 specs. An alternative would be to edit the JavaScript in the onclick attribute to open the link in a new tab.
<button
onclick="window.open('Text.html', '_blank')"
name="link"
style="cursor: pointer"
class="Text"
value="Text.html"
title="Text"
>
Text
</button>
You could wrap an <a> tag around the button instead.
<a href="Text.html" target="_blank">
<button
name="link"
style="cursor: pointer"
class="Text"
value="Text.html"
title="Text"
>
Text
</button>
</a>
I am working on a PHP file upload, but I want the button which opens my uploading page to open it in an pop up window. So it would be like many sites do it, press a button and It opens a pop up where you can upload files.
Here is a code that I tried and it didn't work:
<a href="upload.html" target="_blank">
<input type="button" class="button" value="Upload" />
You have to use type=file
<a href="upload.html" target="_blank">
<input type="file" class="button" value="Upload" />
Try making the input type="file".
Example: input type="file" name="myFile"
If you want to style/change the default button you can by doing so...
read this> custom file upload button
Also close your a tag if your still going to do it that way.
see link-- https://jsfiddle.net/mu3ju64c/1/
<input type="button" value="Open a Popup Window" onclick="window.open('https://www.google.com/javascript/examples/sample_popup.cfm','popUpWindow','height=500,width=400,left=100,top=100,resizable=yes,scrollbars=yes,toolbar=yes,menubar=no,location=no,directories=no, status=yes');">
<p> ----------------------according to your code----------------- </p>
<a href="upload.html" target="_blank">
<input type="file" class="button" value="Upload" />
So this is the simple code for the button to open a certain link
<button class="btn btn-success" onclick="location.href='http://google.com';"> Google</button>
but it opens it on the same page, I want the link to open on a new tab though.
You can use the following.
window.open(
'https://google.com',
'_blank' // <- This is what makes it open in a new window.
);
in HTML
<button class="btn btn-success" onclick=" window.open('http://google.com','_blank')"> Google</button>
plunkr
With Bootstrap you can use an anchor like a button.
<a class="btn btn-success" href="https://www.google.com" target="_blank">Google</a>
And use target="_blank" to open the link in a new tab.
You can also add this to your form:
<form action="https://www.google.com" target="_blank">
Try using below code:
<button title="button title" class="action primary tocart" onclick=" window.open('http://www.google.com', '_blank'); return false;">Google</button>
Here, the window.open with _blank as second argument of window.open function will open the link in new tab.
And by the use of return false we can remove/cancel the default behavior of the button like submit.
For more detail and live example, click here
To open a new tab with a button you just have to choose any of these options:
Open link in a new tab hmtl:
The Website Linked
Button open link in new tab:
<button class="btn btn-success" onclick=" window.open('http://google.com','_blank')"> Google</button>
Open new tab when clicking link html:
<!-- add target="_blank" to open new tab when link is clicked [in HTML]-->
YourText
Use '_blank'. It will not only open the link in a new tab but the state of the original webpage will also remain unaffected.
Try this code.
<input type="button" value="Open Window"
onclick="window.open('http://www.google.com')">
This worked for me.
onClick={() => {window.open('https://www.google.com/');}}
Try this
window.open(urlValue, "_system", "location=yes");
If you're in pug:
html
head
title Pug
body
a(href="http://www.example.com" target="_blank") Example
button(onclick="window.open('http://www.example.com')") Example
And if you're puggin' Semantic UI:
html
head
title Pug
link(rel='stylesheet' href='https://cdn.jsdelivr.net/npm/semantic-ui#2.3.3/dist/semantic.min.css')
body
.ui.center.aligned.container
a(href="http://www.example.com" target="_blank") Example
.ui.center.aligned.container
.ui.large.grey.button(onclick="window.open('http://www.example.com')") Example
In end of the form button can be added like this using target="_blank"
View
I am working on a project, in which needs generation of bill. what is the code for which if we click a button then it will print a hard-copy for the user
try this:
<button onclick="window.print()">Print</button>
you can obviously use <a> or <input> and put onclick="window.print()" in there
You can do it using javascript...Try like this
<input type="button" value="Print This Page" onClick="window.print()" />
I have buttons on a page that look like:
<p>
<a href="view.php">
<input type="button" name="view" value="View Database" />
</a>
</p>
IE does not support these buttons or multiple buttons I am not sure which one. Does anyone know how to fix this to work with IE?
Embedding a button within an <a> tag is not normally done, and really doesn't make any sense. If you want your link to look like a button, then just use the <input> tag with some script on the onclick event, or use css to make your link look button-ish (start by using display:block or display:inline-block);
You can't put an input into the tag, instead, you can create a form, and change your button to a submit one. Then you can choose the target url in the form, like this:
<form action="view.php">
<input type="submit" name="view" value="View Database" />
</form>
I would recommend this over using javascript, because buttons are not designed for navigating a site. If you want to submit information, which is what they are used for, you won't be able to do it so cleanly using javascript.
What exactly are you trying to achieve? If you want a custom button to redirect to view.php, you can use onclick:
<input type="button" name="view" value="View Database" onclick="window.location.href='view.php';" />
or something similar.
<input type="button"
onclick="javascript:document.location='view.php';"
value="View Database"/>
Try with this ugly monster:
<input type="button" name="view" value="View Database" onclick="javascript:window.location='view.php'"/>