- html - 出于某种原因,IE8 对我的 Sass 文件中继承的 html5 CSS 不友好?
- JMeter 在响应断言中使用 span 标签的问题
- html - 在 :hover and :active? 上具有不同效果的 CSS 动画
- html - 相对于居中的 html 内容固定的 CSS 重复背景?
我实现了一个小书签,当点击时将 URL 和标题发送到数据库。我希望首先弹出一个表单,其中包含一个用于添加评论的字段、一个用于编辑页面标题的字段以及一个用于选择从数据库表中填充的类别的下拉字段。
我仍在学习 PHP,几乎没有任何 JS 技能。我不知道如何让小书签调用将提交给数据库的弹出表单或将页面 URL 和标题传递给表单。
到目前为止我使用的代码来自这里 -> http://tutorialzine.com/2010/04/simple-bookmarking-app-php-javascript-mysql/
书签代码:
(function () {
var jsScript = document.createElement('script');
jsScript.setAttribute('type', 'text/javascript');
jsScript.setAttribute('src', '/bookmark.php?url=' + encodeURIComponent(location.href)
+ '&title=' + encodeURIComponent(document.title));
document.getElementsByTagName('head')[0].appendChild(jsScript);
})();
Bookmark.php代码:
// Error reporting:
error_reporting(E_ALL^E_NOTICE);
require "connect.php";
require "functions.php";
// Setting the content-type header to javascript:
header('Content-type: application/javascript');
// Validating the input data
if(empty($_GET['url']) || empty($_GET['title']) || !validateURL($_GET['url'])) die();
// Sanitizing the variables
$_GET['url'] = sanitize($_GET['url']);
$_GET['title'] = sanitize($_GET['title']);
// Inserting, notice the use of the hash field and the md5 function:
mysql_query(" INSERT INTO bookmark_app (hash,url,title)
VALUES (
'".md5($_GET['url'])."',
'".$_GET['url']."',
'".$_GET['title']."'
)");
$message = '';
if(mysql_affected_rows($link)!=1)
{
$message = 'This URL already exists in the database!';
}
else
$message = 'The URL was shared!';
?>
/* JavaScript Code */
function displayMessage(str)
{
// Using pure JavaScript to create and style a div element
var d = document.createElement('div');
with(d.style)
{
// Applying styles:
position='fixed';
width = '350px';
height = '20px';
top = '50%';
left = '50%';
margin = '-30px 0 0 -195px';
backgroundColor = '#f7f7f7';
border = '1px solid #ccc';
color = '#777';
padding = '20px';
fontSize = '18px';
fontFamily = '"Myriad Pro",Arial,Helvetica,sans-serif';
textAlign = 'center';
zIndex = 100000;
textShadow = '1px 1px 0 white';
MozBorderRadius = "12px";
webkitBorderRadius = "12px";
borderRadius = "12px";
MozBoxShadow = '0 0 6px #ccc';
webkitBoxShadow = '0 0 6px #ccc';
boxShadow = '0 0 6px #ccc';
}
d.setAttribute('onclick','document.body.removeChild(this)');
// Adding the message passed to the function as text:
d.appendChild(document.createTextNode(str));
// Appending the div to document
document.body.appendChild(d);
// The message will auto-hide in 3 seconds:
setTimeout(function(){
try{
document.body.removeChild(d);
} catch(error){}
},3000);
}
<?php
// Adding a line that will call the JavaScript function:
echo 'displayMessage("'.$message.'");';
?>
函数.php
<?php
/* Helper functions */
function validateURL($str)
{
return preg_match('/(http|ftp|https):\/\/[\w\-_]+(\.[\w\-_]+)+([\w\-\.,@?^=%&:\/~\+#]*[\w\-\@?^=%&\/~\+#])?/i',$str);
}
function sanitize($str)
{
if(ini_get('magic_quotes_gpc'))
$str = stripslashes($str);
$str = strip_tags($str);
$str = trim($str);
$str = htmlspecialchars($str);
$str = mysql_real_escape_string($str);
return $str;
}
function relativeTime($dt,$precision=2)
{
if(is_string($dt)) $dt = strtotime($dt);
$times=array( 365*24*60*60 => "year",
30*24*60*60 => "month",
7*24*60*60 => "week",
24*60*60 => "day",
60*60 => "hour",
60 => "minute",
1 => "second");
$passed=time()-$dt;
if($passed<5)
{
$output='less than 5 seconds ago';
}
else
{
$output=array();
$exit=0;
foreach($times as $period=>$name)
{
if($exit>=$precision || ($exit>0 && $period<60)) break;
$result = floor($passed/$period);
if($result>0)
{
$output[]=$result.' '.$name.($result==1?'':'s');
$passed-=$result*$period;
$exit++;
}
else if($exit>0) $exit++;
}
$output=implode(' and ',$output).' ago';
}
return $output;
}
// Defining fallback functions for mb_substr and
// mb_strlen if the mb extension is not installed:
if(!function_exists('mb_substr'))
{
function mb_substr($str,$start,$length,$encoding)
{
return substr($str,$start,$length);
}
}
if(!function_exists('mb_strlen'))
{
function mb_strlen($str,$encoding)
{
return strlen($str);
}
}
?>
我想要的最终结果是类似于 Bitly 书签的东西,https://bitly.com/a/tools ,但我只需要帮助将 Bookmarklet 链接到提交到数据库的弹出表单。
我试过环顾其他人的问题,但我找不到任何适用于使用弹出表单提交给数据库的问题。
最佳答案
您可以在书签(javascript)中附加 HTML 表单。
var HTML = '<form action=""><input type="text" name="title" /></form>';
document.appendChild(HTML);
这不是完整的代码,只是可以帮助您完成工作的原理示例。
关于php - 如何让小书签弹出一个表单,将 URL 和标题提交给数据库以及评论,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14406021/
我附上了一个我尝试使用 html/css 实现的示例(如果您看不到图像:名字和姓氏,然后第二行是职位描述)。我希望所有文本(两行)在一个 div 中强制对齐(左和右),但我不确定这是否可能。我尝试了一
我想使两个 h1 元素成为 div 上的标题/页眉。所以每个都在特定的 div 之上。 Youtube Achievements
我想让每个 EditText 对象都有自己的标题,就像 Pure Android 指南中那样 (screenshot) 这个东西有原生支持吗?我想他们也可能会使用带有部分的 ListView ,但这对
是否可以像 UITableView headerView 一样创建 UICollectionView 标题 View ?我的意思是整个集合 View 的标题 View ,而不是每个部分的重复 View
我一直在遵循有关排版的 Google 官方 Material 设计指南 (http://www.google.com/design/spec/style/typography.html),但我发现它们
我目前正在尝试找到可以帮助我从视频文件中提取元数据或信息的 python 库,例如 [ mp4, Mkv, Avi, WebM, mpg ] 格式为例。 我主要从视频文件中提取的主要数据是 [标题、描
你好, 这是我正在尝试做的: 将每个缩略图的内容(img + 标题)居中。我的 img 必须是 span3,标题必须是 span4。 这是我的问题: 我可以获取内容中心,或者标题 float 在 im
我有一个带有导航栏的应用程序,可以从一个 View Controller 导航到下一个 View Controller 。在某些模拟器和设备上导航到下一个 View Controller 时,后退按钮
我遇到了一些非常酷的 t-sql,可以从一个 t-sql 查询中的选定行生成一个逗号分隔的列值列表: SELECT @MyList = ISNULL(@MyList,'') + Title + ',
请确保将 HTML heading 标签只用于标题。不要仅仅是为了生成粗体或的文本而使用标题。 搜索引擎使用标题为您的网页的结构和内容编制索引。 因为用户可以通过标题来快速浏览您的网页,所以用标
我正在使用 wkhtmltopdf 将 html 转换为 pdf。 我想在每个页面中添加标题,但它只显示在第一页(目录)中。 我使用的命令是 "C:\Program Files\wkhtmltopdf
如何使用 ggplot2 显示观察的方向(标题)?有没有办法调整shape=17 (三角形)以便它“指向”下一次观察? 示例代码 library(ggplot2) dat % pivot_wide
我尝试在 cocoa 应用程序中显示/隐藏标题栏。我使用以下代码: if ([window styleMask]==NSResizableWindowMask) { [wind
我有这样的 HTML 标题 http://s1.postimg.org/4ebyk3qwv/image.png 当我编写这段代码时: document.getElementById("TL85_1_
我叫麦克。谢谢你的帮助。 在Wordpress中,我们已经设计了我们的网站,以便在Facebook调试器中og数据尽可能接近youtube。尽管如此,在Facebook上共享视频的方式还是不同的。尽管
从 web 应用程序的客户端,我点击了服务器端路由,它只是第三方 API 的包装器。使用分派(dispatch),我试图让服务器端请求返回 exact header 和第三方 API 对客户端 AJA
从 web 应用程序的客户端,我点击了服务器端路由,它只是第三方 API 的包装器。使用分派(dispatch),我试图让服务器端请求返回 exact header 和第三方 API 对客户端 AJA
我是 SAPUI5 的新手,在导航、侧边栏和标题方面遇到一些问题。我想开发一个带有标题和侧边栏的应用程序。我为此使用“ToolPage”。每个页面都包含工具页,如下所示:
我最近在为客户做的项目中被介绍给Go。他们已经建立了代码库,需要进行一些更改。 我注意到所有的方法,结构等等都有一些奇怪的类似于标题的注释,如下所示: // SomeType ... type Som
我创建了一个采用整个屏幕布局的标题布局(xml 文件)... 我还创建了一个 listView 并将此 header_layout 添加到 listView 中: LayoutInflater inf
我是一名优秀的程序员,十分优秀!