我正努力让你能够:
(已实现)1。在输入表单中输入网址
2。将前缀和后缀我选择添加到网址(prefix =“http://”; postfix =“/ postfixtexthere”)
3。将完整的URL(或值'urlToLoad')加载到Web浏览器
我不确定变量'urlToLoad'是否正确,因为尽管第一次警报正常,但第二次警报仍无效。
我的问题如下:
1.变量'urlToLoad'是否正确?它是否适应输入框中输入的内容?
2.如何让变量'urlToLoad'作为网站浏览器中的网站加载?
希望我已经完成了大部分工作。谢谢你的建议。
function checkDomain() {
alert('function executed successfully');
var testInput = document.getElementById("checker");
var testUrl = textInput.value;
var urlToLoad = "http://" + testUrl + "/postfixtexthere";
alert(urlToLoad);
// instructions
// var urlToLoad = PUT VAR ‘testUrl’ INTO THIS URL, REPLACING ‘__________’: http://__________/postfixtexthere
// THEN LOAD THE URL AS A LINK IN A WEB BROWSER
}
.cta-button, a.cta-button {
border-radius: 6px;
padding: 10px 20px;
border: 1px solid #393939;
cursor: pointer;
background: #ff0;
display: inline-block;
text-align: center;
}
<p>text above the input type</p>
<div id="misc">
<input type="text" placeholder="Enter url" id="checker" value="thisdomain">
</div>
<a class="cta-button" onclick="checkDomain()">Check Link</a>
答案 0 :(得分:1)
尝试在您的本地运行此操作,它应该在新窗口中打开URL
function checkDomain() {
alert('function executed successfully');
var testInput = document.getElementById("checker");
var testUrl = document.getElementById('checker').value;
var urlToLoad = "https://" + testUrl + "/postfixtexthere";
alert(urlToLoad);
window.open(urlToLoad);
// instructions
// var urlToLoad = PUT VAR ‘testUrl’ INTO THIS URL, REPLACING ‘__________’: http://__________/postfixtexthere
// THEN LOAD THE URL AS A LINK IN A WEB BROWSER
}
&#13;
.cta-button, a.cta-button {
border-radius: 6px;
padding: 10px 20px;
border: 1px solid #393939;
cursor: pointer;
background: #ff0;
display: inline-block;
text-align: center;
}
&#13;
<p>text above the input type</p>
<div id="misc">
<input type="text" placeholder="Enter url" id="checker" value="thisdomain">
</div>
<a class="cta-button" onclick="checkDomain()">Check Link</a>
&#13;