Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Web Coding › Adding metadata with jquery - ajax
New Posts  All Forums:Forum Nav:

Adding metadata with jquery - ajax

post #1 of 2
Thread Starter 
I'm trying to get metadata to load into my page when I click a button. The thing is, it works fine if there is no existing metadata. However, if metadata already exists it doesn't work.

Does anyone know whats going on?
Code:
<html>  
<head>  
             
    <meta property="og:title" content="About" />  
    <meta property="og:image" content="http://about.com" />  
    <meta property="og:description" content="About" />  
    <meta property="og:url" content="http://about.com">           
             
     
  <script src="http://code.jquery.com/jquery-latest.js"></script> 
    <script type="text/javascript"> 
     
     
  
/// Append Meta tags 
function setMT(metaName, name, value) { 
        var t = "meta[\'+metaName+\'=\'+name+\']"; 
        var mt = $(t); 
        if (mt.length === 0) { 
            t = '<meta '+metaName+'="'+name+'" />'; 
            mt = $(t).appendTo('head'); 
        } 
        mt.attr('content', value); 
    } 
    </script> 
</head>  
<body> 

<form> 
<input type="button" name="submit" value="I wish I had this" onclick="setMT('property','og:test','teststuff')" /> 
</form> 
</body> 
</html>
    
CPUMotherboardGraphicsRAM
Intel i7-4850HQ  Yes GT 750M 16GB Corsair 
Hard DriveHard DriveOSMonitor
512GB SSD 1TB Buffalo Drivestation OSX Mavericks 15" 2880 x 1800 IPS 
MouseOther
Magic Mouse Mobee Magic Charger 
  hide details  
Reply
    
CPUMotherboardGraphicsRAM
Intel i7-4850HQ  Yes GT 750M 16GB Corsair 
Hard DriveHard DriveOSMonitor
512GB SSD 1TB Buffalo Drivestation OSX Mavericks 15" 2880 x 1800 IPS 
MouseOther
Magic Mouse Mobee Magic Charger 
  hide details  
Reply
post #2 of 2
Code:
function setMT(metaName, name, value)
{
    var t = $('meta[' + metaName + '="' + name + '"]');
    var mt = t.length ? t : $('<meta ' + metaName + '="' + name + '" />').appendTo('head');
    mt.attr('content', value);
}
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Web Coding
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Web Coding › Adding metadata with jquery - ajax