嵌入HTML -每次都有一个新的链接

Embedding with HTML - With a new link each time

本文关键字:有一个 链接 HTML 嵌入      更新时间:2023-09-26

我现在有了这段代码。

<html>
<object data=http://www.tagpro.eu width="850" height="800"> <embed src=http://www.tagpro.eu width="650" height="700"> </embed></object>
</html>

我有一个表格。

<form>
Game:<br>
<input type="text" name="firstname">
<br>
Link:<br>
<input type="text" name="lastname">
</form>

我需要什么:

如果表单,无论链接是什么,将嵌入网站设置为该特定链接。例如,如果在表单中我在链接部分写google,然后点击提交,你会在我的网站上看到google的网页。

谢谢!

我把你的代码改编成这样:

<form id="demo-form">
    Game:<br>
    <input type="text" name="game" id="game" value="bootstrap datepicker">
    <br>
    Link:<br>
    <input type="text" name="link" id="link" value="https://bootstrap-datepicker.readthedocs.org/en/latest/">
    <br />
    <input type="submit" value="Go" />
</form>
<object id="demo-object" data=https://jqueryui.com/datepicker/ width="850" height="800">
    <!--<embed src=http://www.tagpro.eu width="650" height="700"> </embed>-->
</object>

和我使用了一些javascript如下:

document.getElementById("demo-form").onsubmit = function () {
    var game = document.getElementById("game").value;
    var link = document.getElementById("link").value;
    document.getElementById("demo-object").setAttribute('data', link)
    // Return false to prevent the default form behavior
    return false;
}

请检查小提琴。然而,这并不适用于每个站点。例如,我得到了一个错误,试图使用谷歌链接。此外,这个演示可以在Firefox 39.0和Internet Explorer 9中运行,但不能在Chrome 43.0.2357.130中运行。然而,在外部小提琴在Chrome也工作。

如果您需要保持页面刷新之间的选择,一个可能的解决方案是使用jquery-cookie将选择存储在cookie中代码将更改如下:

if ($.cookie("link")) {
    // Restore the last selection from cookie
    document.getElementById("link").value = $.cookie("link");
    document.getElementById("demo-object").setAttribute('data', $.cookie("link"))
}
document.getElementById("demo-form").onsubmit = function () {
    var game = document.getElementById("game").value;
    var link = document.getElementById("link").value;
    document.getElementById("demo-object").setAttribute('data', link)
    // Store the selection in a cookie
    $.cookie("link", link);
    // Return false to prevent the default form behavior
    return false;
}