php 下获取 url 值通过 js 处理后,如何显示在 html 的 iframe 中呢?

2015-05-04 12:20:40 +08:00
 gs038538
需要显示的位置已经在代码那指明,请各路高人指点一二。

url取值方法如下: http://xxx.com/test.php?v=/xxx/xxx.mp3


代码分割线
------------------------------------------------------------------------------------------


<?php
error_reporting(0);
header("Content-Type: text/html; charset=utf-8");
$v=$_GET["v"];
?>
<script type="text/javascript">
var url = '<?php echo $v ?>';
url = url.replace(/\//g,'%252F');
</script>


<iframe class="xxxxx" width="480" height="360" src="http://static.xxx.com/video?outlink_code=9f7144ed&path='这里需要显示js处理后的值,跟前面的部分组成完整的url'" scrolling="no" frameborder="0"></iframe>


代码分割线
------------------------------------------------------------------------------------------


期望的显示结果为
<iframe class="xxxxx" width="480" height="360" src="http://static.xxx.com/video?outlink_code=9f7144ed&path=%252Fxxx%252Fxxx.mp3" scrolling="no" frameborder="0"></iframe>
2642 次点击
所在节点    问与答
11 条回复
ituren
2015-05-04 12:35:22 +08:00
$('iframe.xxxxx').prop('src',$('iframe.xxxxx').prop('src')+url);
gs038538
2015-05-04 12:42:19 +08:00
@ituren 方便给一个相对完整的代码吗?感谢您。
ituren
2015-05-04 12:45:09 +08:00
@gs038538 那要看你iframe的这段代码是怎么生成的,你方便贴你的完整代码么?
gs038538
2015-05-04 13:02:23 +08:00
@ituren <iframe class="xxxxx" width="480" height="360" src="http://static.xxx.com/video?outlink_code=9f7144ed&path='这里需要显示js处理后的值,跟前面的部分组成完整的url'" scrolling="no" frameborder="0"></iframe>

这段代码除了js那是变量外,其余部分是固定的,直接就写到了php里 保持html的输出即可。
现在的做法就是直接写在了php里。帖子那就是我的完整代码啦~~不需要生产iframe。
谢谢您!
b821025551b
2015-05-04 13:10:44 +08:00
$('iframe.xxxxx').prop('src',$('iframe.xxxxx').prop('src')+'这里需要显示js处理后的值,跟前面的部分组成完整的url');
如果多个iframe用到xxxxx,那就给个id吧。
ituren
2015-05-04 13:27:07 +08:00
@gs038538 那你直接用PHP拼接输出就得了, 干嘛还要用JS.
gs038538
2015-05-04 13:29:36 +08:00
@b821025551b 这一句需要放在哪个位置呢?

需要的结果是

<iframe class="xxxxx" width="480" height="360" src="http://static.xxx.com/video?outlink_code=9f7144ed&path=%252Fxxx%252Fxxx.mp3" scrolling="no" frameborder="0"></iframe>

其中
%252Fxxx%252Fxxx.mp3
是被js处理过的~
原值为/xxx/xxx.mp3

这部分:
http://static.xxx.com/video?outlink_code=9f7144ed&path=
是固定的。

您跟ituren指点的方法是一样的,但是我不知道如何去使用,见笑了。谢谢。
gs038538
2015-05-04 13:32:07 +08:00
@ituren 是哦~~
php需要处理 /xxx/xxx.mp3 替换字符串/为%252F %252Fxxx%252Fxxx.mp3
然后放到 iframe的 “ http://static.xxx.com/video?outlink_code=9f7144ed&path= 替换的结果 ”...
然后我又不知道怎么把变量传过去了。
ituren
2015-05-04 13:37:54 +08:00
@gs038538
echo '<iframe class="xxxxx" width="480" height="360" src="http://static.xxx.com/video?outlink_code=9f7144ed&path='.$v.'" scrolling="no" frameborder="0"></iframe>';

不用转换斜杠
gs038538
2015-05-04 13:45:58 +08:00
@ituren 解决了!谢谢~~ '.$v.' 只需要这样就可以了!完全可以百度查到,打扰您了。谢谢。
msg7086
2015-05-04 14:51:02 +08:00
你这个问题问得不对,主要是因为在你的网页上,PHP是比JS先执行的。也就是说,在执行到你这个iframe的时候,上头的js代码还未开始执行呢。

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/188304

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX