Monday 6 February 2012

To add script Tag inside a script


To add <script> Tag inside a <script> Tab via Jquery. we are going to insert <script> inside test111 Div at run time.

$content_top='<div id=test111> gdgdf </div>';

$adbanners='<script> jQuery(document).ready( function($) {
$("body").prepend("'.$content_top.'");

var script = document.createElement("script");
script.type = "text/javascript";
script.src = "https://gist.github.com/1265374.js?file=GetGists.js";
document.write.to = {filename: script.src};
document.getElementById("test111").appendChild(script);

});

</script>';

echo $adbanners;

//** Now add a div after <body> and add script to show Banners in WordPress
At WordPress Plugin file's main page add following hook function
add_action('wp_head', 'my_plugin_topbanner1');
then write the function definition inside the same file

//*** Adding Top banner just after <body>  tag
function my_plugin_topbanner1(){
global $post,$wpdb;
$page="";
$banner=array();
$plugin_url = plugins_url()."/adbanner/images/";
        //** plugins_url() WP function shows the current plugin path
$result = get_option('addbanner_pos');
$banner1=$result;
$banner=json_decode($banner1);
if(is_home()){
$page='home';
}
elseif(is_page()){
$page='page';
}
elseif(is_search()){
$page='search';
}
else{
//default post page
$page='post';
}
if(!empty($page)){
$adbanners="";
$styles="";
$result=$banner->$page;
$temp_banner="";
for($i=0;$i<count($result->content_top);$i++){
if($result->content_top[$i]->position=='ct1'){
$wd=$result->content_top[$i]->width;
$ht=$result->content_top[$i]->height;
$ord1=mt_rand();
$styles="<style>#ct1_ss{overflow:hidden;margin:auto;top:1px;width:".$wd."px;height:auto;padding:1px 0 3px 10px;position:relative}</style>";
$adbanners=$styles."<div id='ct1_ss'><script>document.write('<script language=\"JavaScript\" src=\"http://ad.doubleclick.net/adj/rmm.rmmcreative/delltest_".$wd."x".$ht."exp;sz=".$wd."x".$ht.";ord=".$ord1."?\" type=\"text/javascript\"></scr' + 'ipt>');</script></div>";

}


}
}
echo $adbanners;
}


//** above function will add html code in Wordpress theme blog as follows
<body>
<div id=ct1_ss><script language=Javascript src=http://ad.addouble...></script>
</div>
</body>
Also that script will Run and Load the External URL and will show Ads Images.

No comments:

Post a Comment