[英]Make Select dropdown set session variable to set link target PHP
我想通过下拉菜单为用户提供选项,让图像 map 上的链接在新页面或 iframe(位于图像 map 下方的同一页面上)中打开。
With the code I have both things are happening when either option is selected.
session 变量由下拉菜单正确设置,当我查看源代码时,HTML 使用来自 session 变量的目标进行调整。
我正在使用 PHP MVC。
Select 盒子(tour.php);
<select id="dropdown1" class="select" tabindex="2" onchange="run(this)">
<option value="select">Please Select</option>
<option value="iframe_tour">Open Tour Below Map</option>
<option value="_blank">Open Tour in New Tab</option>
</select>
<input id="mapoption" name="mapoption" id="mapoption" value="<?=$_POST['mapoption']?>" hidden />
图像地图部分(tour.php);
<svg version="1.1" xmlns="http://www.w3.org/2000/svg" xmlns:xlink="http://www.w3.org/1999/xlink" viewBox="0 0 2808 1670">
<image width="2808" height="1670" xlink:href="<?php echo URLROOT; ?>/public/img/map-v2.png"></image>
<a xlink:href="<?php echo URLROOT; ?>/public/tours/beta/index.html#POI_50" id="map_link" target="<?php echo($_SESSION['mapoption']); ?>">
<rect x="2282" y="430" fill="#fff" opacity="0" width="50" height="50"></rect>
</a>
<a xlink:href="<?php echo URLROOT; ?>/public/tours/beta/index.html#POI_111" id="map_link" target="<?php echo($_SESSION['mapoption']); ?>">
<rect x="1428" y="1242" fill="#fff" opacity="0" width="50" height="50"></rect>
</a>
</svg>
页面控制器(Pages.php);
public function tour(){
if(!isLoggedIn()){
redirect('users/login');
}
if($_SERVER['REQUEST_METHOD'] == 'POST'){
$_SESSION['mapoption'] = $_POST['mapoption'];
} else {
$data = [
'menuPleaseChoose' => 'Please Choose from the options',
'menuOptionViewTour' => 'View Tour',
'backToMap' => 'Back To Map'
];
$this->view('pages/tour', $data);
}
}
您可以创建一个 function 将在单击时调用并将图像 url 作为参数传递给此
<a href="javascript:void(0)" onclick="openImage(<image_url>)"></a>
<iframe id="iframeId"></iframe>
<script>
function openImage(url){
$("#iframeId").attr("src", $(this).attr("href"));
}
</script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.