【问题标题】:Open external link in iframe using drop down menu使用下拉菜单在 iframe 中打开外部链接
【发布时间】:2015-04-25 07:25:45
【问题描述】:

我正在使用PHP读取文本文件并生成下拉菜单,该菜单将在选择选项

时将在新选项卡中打开链接
<select onChange="window.location.href=this.value">
<?php
if ($file = @fopen('data-receive.txt', 'r')) {
while(($line = fgets($file)) !== false) {
echo "<option style='width:100px;' value='http://{$line}'>{$line}</option>";
}
fclose($file);
}
?>
</select>

这完美运行,并在新选项卡中打开所选网站。

但是,我在页面上有一个 iframe,我希望在 iframe 中打开下拉菜单选项,而不是在新标签页中打开

<iframe src="demo.html" name="test-frame" width="100%" height="500px"></iframe>

这可能吗? 任何帮助将不胜感激或sms

** 已解决 ** 我变了

window.href.location 

frames['test-frame'].location.href

来源: http://konus.biz/books/DHTML/%D3%F7%E5%E1%ED%E8%EA%20JS%20%EE%F2%20quirksmode/iframe.html#

【问题讨论】:

  • 使用 JavaScript 或 jQuery 更改 iframe src
  • 大声笑,你可以在答案部分给他一个例子。我也可以给他一个,但现在我是坏人,因为你在评论中提到了它。是什么赋予了?等待他的回应?
  • 感谢您的回复我现在找到了解决方案。我用过:frames['test-frame'].location.href

标签: php iframe drop-down-menu hyperlink external


【解决方案1】:
<select id="changeIframe">
<?php
if ($file = @fopen('data-receive.txt', 'r')) {
while(($line = fgets($file)) !== false) {
echo "<option style='width:100px;' value='http://{$line}'>{$line}</option>";
}
fclose($file);
}
?>
</select>

Ifarme:

<iframe id="sourceIframe" src="demo.html" name="test-frame" width="100%" height="500px"></iframe>

Javascript:

var iframe = document.getElementById("sourceIframe");
var changeIframe= document.getElementById("changeIframe");

changeIframe.onchange = function()
{
    iframe.src = this.value;
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-07-06
    • 2012-06-27
    • 1970-01-01
    • 1970-01-01
    • 2018-01-30
    • 2017-09-21
    • 1970-01-01
    • 2022-01-12
    相关资源
    最近更新 更多