Open Button In New Window? March 31, 2024 Post a Comment How would I go about making the button open in a new window, emulating 'a href, target = _blank'? I currently have: Solution 1: Opens a new window with the url you supplied :)<buttonclass="button"onClick="window.open('http://www.example.com');"><spanclass="icon">Open</span></button>Copyhope that helps :)Solution 2: I couldn't get your method to work @Damien-at-SF...So I resorted to my old knowledge.By encasing the input type="button" within a hyperlink element, you can simply declare the target property as so:<ahref="http://www.site.org"target="_blank"><inputtype="button"class="button"value="Open" /></a>CopyThe 'target="_blank"' is the property which makes the browser open the link within a new tab. This attribute has other properties, See: http://www.w3schools.com/tags/att_a_target.asp for further details.Since the 'value=""' attribute on buttons will write the contained string to the button, a span is not necessary.Instead of writing:<element></element>Copyfor most HTML elements you can simply close them with a trailing slash, like so:<element />CopyOh, and finally... a 'button' element has a refresh trigger within it, so I use an 'input type[button]' to avoid triggering the form.Good Luck Programmers.Due to StackOverflow's policy I had to change the domain in the example: https://meta.stackexchange.com/questions/208963/why-are-certain-example-urls-like-http-site-com-and-http-mysite-com-blockeSolution 3: <inputtype="button" onclick="window.open(); return false;" value="click me" /> Copyhttp://www.javascript-coder.com/window-popup/javascript-window-open.phtmlSolution 4: You can acheive this using window.open() method, passing _blank as one of the parameter. You can refer the below links which has more information on this.http://www.w3schools.com/jsref/met_win_open.asphttp://msdn.microsoft.com/en-us/library/ms536651(v=vs.85).aspxHope this will help you.Solution 5: If you strictly want to stick to using button,Then simply create an open window function as follows:<script>functionmyfunction() { window.open("mynewpage.html"); } </script>CopyThen in your html do the following with your button:JoinSo you would have something like this:<body><script>functionjoinfunction() { window.open("mynewpage.html"); } </script><buttononclick="myfunction()"type="button"class="btn btn-default subs-btn">Join</button>Copy Share Post a Comment for "Open Button In New Window?"
Post a Comment for "Open Button In New Window?"