Would a search bot have trouble with finding/indexing this link in PHP code from an onclick event?

StackOverflow https://stackoverflow.com/questions/21742373

문제

I wanted to make my site use more PHP in order to save space on HTML code and I wanted to try using this code to make a menu that would launch different divs containing different pages or information per se, I was wondering if search bots would have difficulty navigating such a maze because of php or Javascript or both?

Here's the code,

<?php
 if($_GET['button1']){fun1();}
 if($_GET['button2']){fun2();}

 function fun1()
 {
   //creates a div with a link to google
    echo'<a href = "http://www.google.com"><div style = "height:100px; width:20px; top:100px; left:100px; background-color: black;"></div></a>';   
 }
 function fun2()
 {
 //creates a div with a link to yahoo
   echo'<a href = "http://www.yahoo.com"><div style = "height:200px; width:40px; top:200px; left:200px; background-color: red;"></div></a>';
 }
?>

<!DOCTYPE html>
<html lang="en">
  <head>
    <title></title>
  </head>
  <body>
    <button id="btnfun1" name="btnfun1" onClick='location.href="?button1=1"'>Update to 1</button>
    <button id="btnfun2" name="btnfun2" onClick='location.href="?button2=1"'>Update to 2</button>
  </body>
</html>
도움이 되었습니까?

해결책

  1. Generally bots don't render JavaScript, so avoid that if you want those links indexed properly. Why are you even using onClick there?
  2. PHP is not delivered to the client/bot, only its output which is generally HTML. So long as your output is valid the bots should crawl it just fine.
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top