php code functions.php中的移动检测Innerhtml
在我的functions.php wordpress文件中,我有以下代码:php code functions.php中的移动检测Innerhtml,php,mobile,innerhtml,detect,Php,Mobile,Innerhtml,Detect,在我的functions.php wordpress文件中,我有以下代码: function mia_on_load_script() { // Not our page, do nothing if( !is_page( 'test' ) ) return; ?> <script type="text/javascript"> function change1(){ document.getElementById('mydiv')
function mia_on_load_script()
{
// Not our page, do nothing
if( !is_page( 'test' ) )
return;
?>
<script type="text/javascript">
function change1(){
document.getElementById('mydiv').innerHTML = '<div id="1" style="margin-left: 0px; padding: 0px; float: left; width: 640px; height: 392px; border: 0px;"><iframe style="border: 0 none transparent;" src="//www.ustream.tv/embed/******?wmode=direct&autoplay=true" width="640" height="392" frameborder="no"></iframe></div><div id="2" style="margin-left: 0px; padding: 0px; float: left; width: 320px; height: 392px; border: 0px;"><iframe style="border: 0 none transparent;" src="//www.ustream.tv/socialstream/******" width="320" height="392" frameborder="no"></iframe></div><div id="addthisc" style="margin:0px; text-align: center; background-color:#0A0A0C; paddding: 0px 0px 0px 0px; width: 640px; height: 100%; border:0px;"><div class="addthis_native_toolbox"></div></div>';
}
</script>
<?php
};
add_action( 'wp_head', 'mia_on_load_script' );
?>
加载脚本()上的函数mia\u
{
//不是我们的页面,什么都不做
如果(!is_页('test'))
返回;
?>
函数change1(){
document.getElementById('mydiv')。innerHTML='';
}
网页测试中的Html代码如下:
<input type="button" onclick="change1()" value="change html in mydiv " />
此函数用于更改div中的html:“mydiv”单击按钮“更改mydiv中的html”
我不想用javascript点击一个按钮来改变html,而是想在移动浏览器发出请求时在网页加载时改变它,这样我就可以
决定使用
Mobile_Detect.php类()
我以前的职能是:
function mia_on_load_script()
{
// Not our page, do nothing
if( !is_page( 'test' ) )
return;
?>
<?php
require_once(TEMPLATEPATH . '/MyScript/Mobile_Detect.php');
$detect = new Mobile_Detect;
if ( $detect->isMobile() ) {
???????????????????????????????????????????????????????????
???????????????????????????????????????????????????????????
???????????????????????????????????????????????????????????
}
?>
<?php
};
add_action( 'wp_head', 'mia_on_load_script' );
?>
加载脚本()上的函数mia\u
{
//不是我们的页面,什么都不做
如果(!is_页('test'))
返回;
?>
那个么,我必须插入哪一段代码来代替问号来更改html以代替“document.getElementById('mydiv').innerHTML”?
感谢使用
窗口。addEventListener('load',…)
:
加载脚本()上的函数mia\u
{
如果(是第页(“测试”))
{
需要_once(TEMPLATEPATH.'/MyScript/Mobile_Detect.php');
$detect=新手机检测;
如果($detect->isMobile())
{
?>
addEventListener('load',function())
{
document.getElementById('mydiv')。innerHTML='';
});
function mia_on_load_script()
{
if(is_page('test'))
{
require_once(TEMPLATEPATH . '/MyScript/Mobile_Detect.php');
$detect = new Mobile_Detect;
if($detect->isMobile())
{
?>
<script> <!-- No "type" attribute for HTML 5 -->
window.addEventListener('load', function()
{
document.getElementById('mydiv').innerHTML = '<div id="1" style="margin-left: 0px; padding: 0px; float: left; width: 640px; height: 392px; border: 0px;"><iframe style="border: 0 none transparent;" src="//www.ustream.tv/embed/******?wmode=direct&autoplay=true" width="640" height="392" frameborder="no"></iframe></div><div id="2" style="margin-left: 0px; padding: 0px; float: left; width: 320px; height: 392px; border: 0px;"><iframe style="border: 0 none transparent;" src="//www.ustream.tv/socialstream/******" width="320" height="392" frameborder="no"></iframe></div><div id="addthisc" style="margin:0px; text-align: center; background-color:#0A0A0C; paddding: 0px 0px 0px 0px; width: 640px; height: 100%; border:0px;"><div class="addthis_native_toolbox"></div></div>';
});
</script>
<?php
}
}
}
add_action('wp_head', 'mia_on_load_script');