HTML重定向脚本帮助需要修改以显示重定向URL而不是重定向

时间:2015-07-26 17:21:40

标签: javascript html redirect javascript-events

这是剧本:

<HTML>
    <HEAD>
        <SCRIPT type="javascript">
        function goToPage(var url = '')
        {
        var initial = "http://www.blossompromotions.com/-p-";
        var extension = "html";

        window.location(initial+url+extension);
        }
        </SCRIPT>
        <TITLE>Redirect 1</TITLE>
        <BASE HREF="http://www.blossompromotions.com/">
    </HEAD>
    <BODY>
        <P></P>
        <FORM name="something" action="#">Label 
            <INPUT type="text" name="url" value="" onSubmit="goToPage(this.value)" />
            <INPUT type="submit" value="GO" />
        </FORM>
    </BODY>
</HTML>

这会重定向到网址,但我希望用户能够查看和复制网址。请告诉命令而不是goToPage,它将在屏幕上显示用户要复制的URL。

2 个答案:

答案 0 :(得分:1)

您可以使用JavaScript执行此操作,并在输入文本中添加ID

function goToPage(var url = '')
{
var initial = "http://www.blossompromotions.com/-p-";
var extension = "html";

document.getElementById('url').value=initial+url+extension ; 
}

<FORM name="something" action="#">
Label 
    <INPUT id="url" type="text" name="url" value="" onSubmit="goToPage(this.value)">
    <INPUT type="submit" value="GO">
</FORM>

答案 1 :(得分:0)

&#13;
&#13;
function goToPage(url){
var initial = "http://www.blossompromotions.com/-p-";
var extension = ".html";
var link = document.getElementById('gotoURL');
link.innerHTML = url ? initial+url+extension : '' ;
link.href = initial+url+extension;
}
&#13;
<FORM name="something" action="#">
Label 
<INPUT type="text" name="url" value="" onkeyup="goToPage(this.value)">
<INPUT type="submit" value="GO">
</FORM>
<a href="" id="gotoURL"></a>
&#13;
&#13;
&#13;