dtmu88600 2013-09-04 20:25
浏览 74
已采纳

iframe中的网址随机数

I'm trying to create an iframe which loads a random page from another site. The URL is simply the domain, followed by a number. So far, I have tried PHP:

$number = int rand(0,450000);
$page = 'http://www.example.com/'$number;

Problem is, I don't know how to create the iframe, so that $page goes into the <iframe src=""></iframe>

Perhaps something with javascript? I'm unfamiliar with JS, though. All I know is this from google:

var randomnumber=Math.floor(Math.random()*450001)

But again, I have no idea how to proceed.

  • 写回答

1条回答 默认 最新

  • dongyixiu3110 2013-09-04 20:27
    关注
    <?php
      $rand = rand(0,450000);
      $page = 'http://example.com/' . $rand;
    ?>
    <!-- ... -->
    <iframe src="<?php echo $page; ?>"></iframe>
    <!-- ... -->
    

    Or, more concisely:

    <iframe src="http://example.com/<?= rand(0, 450000); ?>"></iframe>
    

    <?= ... ?> is synonymous with <?php echo ... ?>, btw.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥50 安卓adb backup备份子用户应用数据失败
  • ¥20 有人能用聚类分析帮我分析一下文本内容嘛
  • ¥15 请问Lammps做复合材料拉伸模拟,应力应变曲线问题
  • ¥30 python代码,帮调试
  • ¥15 #MATLAB仿真#车辆换道路径规划
  • ¥15 java 操作 elasticsearch 8.1 实现 索引的重建
  • ¥15 数据可视化Python
  • ¥15 要给毕业设计添加扫码登录的功能!!有偿
  • ¥15 kafka 分区副本增加会导致消息丢失或者不可用吗?
  • ¥15 微信公众号自制会员卡没有收款渠道啊