1

I would like to open a new tab with sent condition, my code now:

<span>Type <b>Link</b>: <input id="myInput" value=""> and click <b>Enter</b> 
<button style="display: none;" id="myButton" onclick="myFunction2()">Go!</button>

[...]

<script>
var websitelink = '"https://www.' + myInput + '.com"';
function myFunction2() {
    window.open(websitelink);
}

but all it does is opening a new blank tab. Any idea?

Thanks.

1
  • Open your developer's tools in your browser (F12) and look at the Console tab. Any errors reported there? And, you do have a closing <script> tag as well, right? Commented Oct 26, 2018 at 12:23

1 Answer 1

2

You have more quotes than you need in your websitelink

It should work with this:

var websitelink = "https://www." + myValue + ".com";

Here it's a snippet:

The code in a website should work but the snippet will not work because the allow-popups permission is not set in the iframe

Blocked opening 'https://www.google.es.com/' in a new window because the request was made in a sandboxed frame whose 'allow-popups' permission is not set.

function myFunction2() {
    var myInput = document.getElementById("myInput").value;
    var websitelink = "https://www." + myInput + ".com";
    window.open(websitelink);
}
<span>Type <b>Link</b>: <input id="myInput" value=""> and click <b>Enter</b> 
<button style="" id="myButton" onclick="myFunction2()">Go!</button>

Sign up to request clarification or add additional context in comments.

3 Comments

@Maciej This is the correct answer. If it's still not working you have some other issue.
@Maciej Check it out the edit of my answer, it probably what you are experimenting. You can see the error message in the console.
Popup blockers do not typically block a new window that opens as a result of a user action, like button click because not all pop ups are bad. They only block pop ups when the code automatically generates the pop up without user intervention.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.