我有一个脚本来获取在meta标签中使用的基本网址,但它似乎没有工作......
第一:我的脑袋看起来像这样......<head>
<meta charset='utf-8'>
<title>****</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="****" />
<meta name="keywords" content="****" />
<!--FACEBOOK OPEN GRAPH META TAGS - THIS IS WHAT GETS POSTED-->
<meta property="og:site_name" content="*****"/>
<meta property="og:title" content="<!-- TMPL_VAR street_no --> <!-- TMPL_VAR street --> <!-- TMPL_VAR city -->, <!-- TMPL_VAR state --> <!-- TMPL_VAR zip --> | $<!-- TMPL_VAR NAME=price -->" />
<meta property="og:description" content="Listing found at..." />
<meta property="og:type" content="website" />
<meta property="og:url" />
<meta property="og:image" content="http://sandbox.dev.activemls.com/property/photo/<!-- TMPL_VAR listing_id -->/1" />
<!--END FACEBOOK OPEN GRAPH-->
<link rel="stylesheet" type="text/css" href="/static/bootstrap/css/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="/static/css/shell.css" />
<link rel="shortcut icon" href="/static/images/favicon.png" type="image/x-icon" />
<script src="http://maps.google.com/maps/api/js?sensor=false&language=en" type="text/javascript"></script>
<script src="/static/js/jquery-1.9.1.js "></script>
<script src="/static/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/static/js/gmap3.js"></script>
<script type="text/javascript" src="/static/js/shell.js"></script>
<script>alert(base)</script>
</head>
我的剧本是......
function baseURL () {
base = window.location.protocol+"//"+window.location.host+"/";
return base;
};
$("meta[property='og:url']").attr("content", base+"/property/detail/<!-- TMPL_VAR mls_number -->");
当我加载页面时,og:url仍为空白...
当前修订
来自shell.js的:
/*******************************/
/* GET BASE URL
/*******************************/
function baseURL () {
base = window.location.protocol+"//"+window.location.host+"/";
$("meta[property='og:url']").attr('content', base+'/property/detail/<!-- TMPL_VAR mls_number -->')
return base;
};baseURL();
console.log(base);
HTML:
<head>
<meta charset='utf-8'>
<title>A.A. Green Realty, Inc. - Wood Co. Real Estate Experts</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="AAGreen Realty, Inc. serves Northwestern home buyers and sellers in Wood County, Perrysburg, and the surrounding areas." />
<meta name="keywords" content="Wood County Ohio Real Estate, Wood County Ohio Properties, Wood County Ohio Homes, Wood County Ohio Houses, Wood County Ohio Housing, Wood County Ohio New Homes" />
<!--FACEBOOK OPEN GRAPH META TAGS - THIS IS WHAT GETS POSTED-->
<meta property="og:site_name" content="Welles Bowen-Gio Realty, Inc."/>
<meta property="og:title" content="<!-- TMPL_VAR street_no --> <!-- TMPL_VAR street --> <!-- TMPL_VAR city -->, <!-- TMPL_VAR state --> <!-- TMPL_VAR zip --> | $<!-- TMPL_VAR NAME=price -->" />
<meta property="og:description" content="Listing found at A.A. Green Realty" />
<meta property="og:type" content="website" />
<meta property="og:url" />
<meta property="og:image" content="http://sandbox.dev.activemls.com/property/photo/<!-- TMPL_VAR listing_id -->/1" />
<!--END FACEBOOK OPEN GRAPH-->
<link rel="stylesheet" type="text/css" href="/static/bootstrap/css/bootstrap.css" />
<link rel="stylesheet" type="text/css" href="/static/css/shell.css" />
<link rel="shortcut icon" href="/static/images/favicon.png" type="image/x-icon" />
<script src="http://maps.google.com/maps/api/js?sensor=false&language=en" type="text/javascript"></script>
<script src="/static/js/jquery-1.9.1.js "></script>
<script src="/static/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="/static/js/gmap3.js"></script>
<script type="text/javascript" src="/static/js/shell.js"></script>
</head>
演示网站的网址: http://aagreen.dev.activemls.com